Now let’s look at an alternative, using named actions within one action state, as shown in
Listing 12-20.
Listing 12-20.Using Named Actions to Invoke Multiple Actions As Part of a Chain
<action-state id="setupForm">
<action name="exposeFormObject" bean=formAction" method="exposeFormObject"/>
<action name="setupReferenceData" bean="formAction" method="setupReferenceData"/>
<action name="setupDateChooser" bean="formAction" name=""setupDateChooser"/>
<transition on="setupDateChooser.success" to="nextState"/>
</action-state>
The nameattribute provides a namespace for the action event id, allowing you to distin-
guish the same event idfrom different actions. You may choose to transition on an event
returned by any of the actions, but you are not required to provide a transition for each event.
Essentially Spring Web Flow will execute all actions until a matching transition is found. If
there is no transition that matches the result of the last action, a NoSuchTransitionException
will be thrown.
FormAction
Form processing is a common requirement for many web applications, and Spring Web Flow
provides the org.springframework.webflow.action.FormActionimplementation to handle
this. FormActionprovides the following convenience methods, as listed in Table 12-8.
Table 12-8.FormAction Methods
Method Purpose Life Cycle
exposeFormObject() Instantiate and expose the form object Before the form is displayed.
in the configured scope.
bind() Update the form from the supplied After the form has been
properties. submitted.
validate() Perform validation of the populated After the form has been
form. submitted and bound.
The SimpleFormControllerin Spring MVC may appear to be similar, but the appearance is
deceiving. SimpleFormControllerimplements a predefined work flow to manage a single-page
form flow, and it allows you to customize that work flow by overriding template methods.
FormActiondoes notimplement such a predefined work flow; rather, it implements and
exposes methods that youare responsible for calling.
This separation of command and controller logic is generally a good thing. One of the
limitations of a template-based approach is that you are restricted to the work flow exposed
by the superclass. If your work flow differs considerably from the template, things start to get
complex. This is not an issue with Spring Web Flow, as you are in full control over the flow and
when certain actions are executed.
For convenience, FormActiondoes provide some coarse-grained methods that implement
the same functionality as methods in SimpleFormController, and we list these in Table 12-9.
360 CHAPTER 12 ■ADVANCED SPRING WEB FLOW