(Quick Reference)
f:field
Description
f:field renders the widget using either
f:widget or the tag body accompanied by any surrounding markup, typically a container, a
label tag and any validation messages.
By default the
f:field tag will output:
<div class="fieldcontain">
<label for="foo">Foo</label>
<!-- the widget as generated by f:widget or the tag body -->
</div>
The intention is that
f:field should typically be used
without a tag body. For example:
<f:field bean="person" property="name"/>
In which case the tag will use
f:widget to generate an appropriate input. Alternatively in more specialized cases you can give
f:field a tag body. For example:
<f:field bean="person" property="name">
<g:textField name="${property}" value="${value}"/>
</f:field>
Since version 1.5 you can specify which specific templates are going to be used on the view.
You can accomplish this using new attributes:
wrapper ,
widget and
templates . (See attributes section)
// renders _fields/bootstrap3/_wrapper.gsp:
<f:field bean="person" property="name" wrapper="bootstrap3"/>// renders _fields/maskedInput/_widget.gsp:
<f:field bean="person" property="name" widget="maskedInput"/>// renders _fields/maskedInput/_wrapper.gsp and _fields/maskedInput/_widget.gsp:
<f:field bean="person" property="name" templates="maskedInput"/>
See
Customizing Field Rendering for details of the parameters passed to the tag body.
The
f:field tag handles embedded domain properties in a special way. See
Embedded Properties for details.
Attributes
Name | Required? | Description |
---|
bean | yes for f:widget if not inside f:with , optional for f:field | The bean whose property is being rendered. This can be the object itself or the name of a page-scope variable. |
property | yes | The path to the property. This can include any level of nesting and numeric or string indexes. For example employees[0].address[home].street is a valid path. |
value | | Overrides the actual value of the property. |
default | | A default value for the property that will be used if the actual property value is falsy . |
required | | Overrides the required status of the property. By default this is worked out based on the property's constraints. |
invalid | | Overrides the validity of the property. By default this is worked out using the bean's errors property for domain and command objects. |
label | | Overrides the field label passed to the template. This value may either be an i18n key or a literal string. |
prefix | | A string (including the trailing period) that should be appended before the input name such as name="${prefix}propertyName" . The label is also modified. |
wrapper | | Specifies the name of the folder inside _fields where the _wrapper.gsp template is located. |
widget | | Specifies the name of the folder inside _fields where the _widget.gsp template is located. |
templates | | Specifies the name of the folder inside _fields where the _wrapper.gsp and _widget.gsp templates are located. It is a shorthand for specifying both ( wrapper and widget ). |
Any additional attributes are passed to the rendered template. Any additional attributes prefixed with
widget-
are instead passed to the widget template or rendered on the default input.