When invoked, setupFormwill create an instance of the purchase.domain.Purchaseform
object class and place it in flow scopeunder the name purchase. This automatically exposes
the Purchaseobject to the views by that name, which will allow correct prepopulation fields
based on default values.
When bindAndValidateis invoked it will bind incoming request parameters to the existing
purchasebean managed in flow scope. After successful data binding, the configured Validator
will then validate the new state of the bean.
■NoteFormActionis a very rich object and will be investigated further in Chapter 12.
Testing the Flow Execution
At this point you nearly have a syntactically correct flow definition whose execution can be
unit tested outside of the container. By filling in temporary state “placeholders” for the unde-
fined states, you’ll correct the remaining syntax errors. Refer to Listing 11-7.
Listing 11-7./WEB-INF/flows/purchase-flow.xmlAdding End State placeholders
<flow start-state="enterPurchaseInformation">
<view-state id="enterPurchaseInformation" view="purchaseForm">
<entry-actions>
<action bean="formAction" method="setupForm"/>
</entry-actions>
<transition on="submit" to="requiresShipping">
<action bean="formAction" method="bindAndValidate"/>
</transition>
<transition on="cancel" to="cancel"/>
</view-state>
<end-state id="requiresShipping"/>
<end-state id="cancel"/>
<import resource="purchase-flow-context.xml"/>
</flow>
With the requiresShippingand cancelplaceholder, when either the submitor canceltransi-
tions are executed, the flow terminates. Once a test verifies that the enterPurchaseInformation
controller logic executes successfully, you’ll properly implement the requiresShippingstate, as
well as the remaining states of the flow.
Extending AbstractFlowExecutionTests
How do you test the execution of the flow defined so far? Spring Web Flow ships support
classes within the org.springframework.webflow.testpackage. This support includes conven-
ient base classes for implementing flow execution tests, as well as mock implementations of
core Web Flow constructs such as the RequestContextto support unit testing flow artifacts
such as Actions in isolation.
324 CHAPTER 11 ■INTRODUCTION TO SPRING WEB FLOW