Download

Get Loom

Decorators

Decorators

Any Loom tag (any tag that extends AbstractLoomTag) has an associated Decorator instance that gets called before and after the tag itself. Decorators are searched by looking for the tag class name, then each superclass.

The default decorator can be overriden using the "decorator" attribute. The default decorator for form fields will render the field label, input field, and associated error message, if any.

<!-- print the value after this hidden field -->
<l:inputHidden name="mortgage.id" decorator="print"/>

<!-- print label and field -->
<l:inputText name="mortgage.name"/>

<!-- print just the field, without label -->
<l:inputText name="mortgage.address" decorator="none"/>

<!-- print the field as text. No field will be written -->
<l:inputText name="mortgage.address" renderAsText="true"/>

Input field decorator tuning

The default input field decorator uses some tag attributes to modify the generated HTML:

  • renderLabel: if false, the form input field will not generate any label. Defaults true.
  • translateLabel: true to translate the label before rendering. Defaults true.
  • renderAsText: if true, plain text will be rendered instead of a form field (label options still apply). Defaults to false.
  • renderErrorDisplayComponent: render a separate error display component. If false, the component errors will be shown in a common error display rendered by an <l:errors> tag. Defaults to true.
  • labelPosition: Sets the position of the input component label. Default is left for all fields but checkboxes and radio buttons

Some of these values can be changed in the containing form, in which case the value will be the default for all nested input fields.

Registered decorators

New decorators can be registered at TagDecoratorRepository. The default list is as follows; to use them, just specify the decorator using the "decorator" attribute.

  • print: print the field value. Intended to use on <inputHidden> fields.
  • inline and nested: the type of menu decorator to use. Inline will display the menu items as a single list of links, while nested will use a hierarchy of nested <ul>.
  • link-only: when used with a <l:url> tag, only the link will be written without the tag.
  • read-only: use the ReadOnlyDecorator. This is used internally by the renderAsText attribute.

Render as text

When renderAsText=true, the field will be rendered as output text, for display-only purposes. This means that instead of the usual label and text field, the browser will see something like this:

<p>
<span>File name:</span> foo.txt
</p>

When rendering as text, each component behaves different:

  • InputText renders the field value. If the size property has been set and the field value is bigger than that, it gets truncated and replaced with an ellipsis ("Some very big val...")
  • InputSelect and InputRadio displays the selected option label
  • InputCheckbox displays the translated string of the field name + ".true" or ".false", depending on the value

Internally, renderAsText is implemented using a ReadOnlyDecorator, so it can be overriden by specifying your own decorator instead.