Expert Spring MVC and Web Flow

(Dana P.) #1

Listing 11-2./WEB-INF/flows/purchase-flow.xmlContaining Transitions








The preceding transition instructions can be read, “On the occurrence of the submit
event, transition to the requiresShippingstate; on the occurrence of the cancelevent, transi-
tion to the cancelstate.”


Actions


At this point you have defined a simple view state that will display a form and respond to
“submit” and “cancel” events. You have yet to define the target states of the above transitions,
which is the next logical step.
Before continuing, however, consider some requirements typical of most form views.
Forms usually need to be prepared before their display; that is, it is often the case that view
prerender logic needs to be executed. This logic might load the “backing form object” that will
be edited in the form, or it might load a collection of objects from the database for display in a
drop-down menu or select box.
Similarly, when a form is submitted, there is typically submit or postback logic that needs
to execute. This logic is usually concerned with data binding (the process of copying form
input parameters into properties of the “backing form object”) and data validation (the
process of validating the new state of the form object).
In Spring Web Flow, you invoke arbitrary command logic such as prerender and postback
logic by executing an action that implements the core org.springframework.webflow.Action
interface, as shown in Listing 11-3.


Listing 11-3.org.springframework.webflow.Action


public interface Action {
Event execute(RequestContext context);
}


The interface is simple, consisting of a single method. An Actionis expected to execute
arbitrary logic when invoked in the context of a request. Once execution has completed, a
result event (or outcome) is returned which the calling flow may respond to.
An Actioncan do whatever you want it to do, and we’ll cover a number of out-of-the-box
implementations in this book. What is important to understand now is the Actionis the core
construct for executing application code from a flow, and there are many opportunities to
execute Actions within the life cycle of a flow. Table 11-4 provides the available execution
points within a flow life cycle.


CHAPTER 11 ■INTRODUCTION TO SPRING WEB FLOW 321
Free download pdf