grails:
plugin:
fields:
localizeNumbers: false
1. f:widget
Purpose
f:widget
renders an appropriate widget for a property, for example an <input type="text">
element for a String
property or a <select>
for an enum.
Using f:widget directly will only be necessary for very specialized cases, usually it will be invoked via f:field .
|
Attributes
f:widget
accepts exactly the same attributes as the f:field tag (except for wrapper
and templates
attributes).
Default rendering
The <f:widget/>
tag will will by default use sensible defaults when rendering String
, Number
, Boolean
, URL
, Enum
, Date
and associations like oneToOne
, oneToMany
, manyToOne
and manyToMany
.
In a few cases it is possible to control which default widget to use, by specifying it in the beans constraints
.
The following happens with these types:
String
By default, properties instance of String
renders a <g:field type="text">
type field, but the constraints
in the bean will alter this in these cases:
|
Rendered Widget type |
|
|
|
|
|
|
|
|
|
|
Numeric and primitive types
By default, properties instance of Number
renders a <g:field type="number">
or <:field type="number decimal"/>
type field, but the constraints
in the bean will alter this in these cases:
|
Affects the rendered widget |
|
Sets the |
|
Set the |
|
Set the |
By default, the value is formatted with the default numberFormatter
based on the request locale.
This behavior can be turned off in the configuration by setting:
Boolean
Renders a <g:checkBox/>
URL
Renders a <g:field type="url"/>
Enum
enum
types always renders a <g:select/>
with all the values in the type. To render a subset of enum
values, the inList
constraint can be used.
Date, Calendar, java.sql.Date and java.sql.Time
Renders a <g:datePicker/>
. If Date
, Calendar
, or java.sql.Date
then precision
is set to day
, if java.sql.Time
then minute
byte[], Byte[], Blob
Renders a <g:field type="file"/>
oneToOne
, manyToOne
or manyToMany
associations
All these associations renders a <g:select/>
and if association has a nullable: true
constraint, then a noSelection
attribute is added.
For the manyToMany
association, the multiple
attribute is set.
oneToOne and `manyToOne
renders a
'oneToMany' association
The oneToMany
association does not render an input type field, but does instead render a list of links to the associated objects.
Example of overriding a _widget.gsp
If you want to override a f:widget
for a String
, then create a file with content like this:
<g:textField name="${property}" value="${value}" required="${required}" class="form-control"/>