Grails Cookbook - A collection of tutorials and examples

Grails textField Tag Example

The Grails textField tag (<g:textField>) can be used to render a input of type 'text' (a text field) form control. This will show a simple example on how to use this tag.

Examples

Assuming this controller code action will pass a bean with property values

def create = {
    Person person = new Person()
    person.firstName = "John"
    person.lastName = "Doe"
    person.remarks = "Test Remarks"
    [person:person]
}

Specify Name

This Code:

<g:textField name="firstName" value="${person.firstName}" />

Will render:

<input type="text" name="firstName" value="John" id="firstName" />

Notice that name and id have the same value when no value for id is specified.

Specify Name And ID

This Code:

<g:textField name="firstName" id="firstNameTestId" value="${person.firstName}" />

Will render:

<input type="text" name="firstName" id="firstNameTestId" value="John" />

CSS Class


This Code:
<g:textField name="firstName" class="xyz" value="${person.firstName}" />

Will render:

<input type="text" name="firstName" class="xyz" value="John" id="firstName" />

Style

This Code:

<g:textField name="firstName" style="color:#ff0000;" value="${person.firstName}" />

Will render:

<input type="text" name="firstName" style="color:#ff0000;" value="John" id="firstName" />


Other Grails Tag Examples


Tags: Grails Tag, textField