A decorator is a commonly-used Java programming pattern that enables programmers to extend the functionality of an object in a way that is transparent to users of the object. Decorators are used in the Content Store to add functionality to content items and section pages. You need Java programming skills to create a decorator, but not to make use of one in your templates.

Decorators can be used in CUE applications to modify the properties or field values returned from content items in various ways. The code examples used in this section, for example, can be used to:

  • Automatically convert a content item's title to upper case

  • Automatically expand any collection content items (see A Complex Decorator Example) in a related content item's relation

All the functions that can be performed with decorators can also be performed in other ways. You could, for example, either include in-line Java code in your templates or write your own JSP tags. However, using decorators has a number of advantages:

  • No in-line code ensures simpler, more legible templates

  • The template developer does not need to remember to use special tags

  • Decorators only need to be declared in the content-type resource: once this has been done they are fully automatic and completely transparent

  • They can be re-used simply by adding declarations to the content-type resource

Obviously, decorators are not always the right solution. If, for example, you want content item titles to be upper case in some contexts but not in others, then you would need to use in-line code or a custom tag rather than a decorator. And in other cases it may be better to use transaction filters (see Transaction Filters).

Note that if you are using memcached, the decorator must be serializable.