Expert Spring MVC and Web Flow

(Dana P.) #1

Listing 8-25.Example of the #formInput Macro



Depart From:
#springFormInput("searchFlights.departFrom" "")
Depart On:
#springFormInput("searchFlights.departOn" "")
(yyyy-MM-dd HH)

#springFormInputperforms a #springBindon the path supplied as the first parameter and
outputs an input field in HTML based on this bind. The second parameter, in the example an
empty string, is used to convey additional attributes that the input field should have. This is
useful for generating styleor classattributes on the output. The preceding fragment will be
rendered into the HTML in Listing 8-26 (assuming this form is not being shown after a valida-
tion failure).


Listing 8-26.Rendered HTML from the Velocity Macro



Depart From:

Depart On:

(yyyy-MM-dd HH)

When the form is shown after a validation failure, the value attributes of the input fields
will contain any text entered by the user prior to submitting the form.


■Tip In Spring 1.2.6 the macros will also add an idattribute to the form fields that will have the same
value as the nameattribute. This makes the fields more accessible to JavaScript, for example.


#springFormHiddenInput and #springFormPasswordInputare basically similar to the stan-
dard #springFormInputmacro. The only difference being that the input type is set to hidden
or password, respectively. Note that for password fields, the value will never automatically be
populated in the event that the form is redisplayed due to validation failure. This is for security
reasons.
The next four macros are again all related to each other. They can all display groups of
options either as a single select drop-down list, a multiselect list, radio buttons, or check
boxes. With radio buttons and check boxes you must specify what the separator is between
each element in the group—for example,
to show columns or  to show them in a
row. Let’s see an example of two of these in action. The actual options are created by the
Controllerand made available as part of the model. You might do this dynamically or
perhaps through the referenceData()methods in your Controller.


CHAPTER 8 ■SUPPORTED VIEW TYPES 245
Free download pdf