Expert Spring MVC and Web Flow

(Dana P.) #1
Listing 12-3.The Purchase Product Flow Definition

<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>

<decision-state id="requiresShipping">
<if test="${flowScope.purchase.shipping}" then="enterShippingDetails" ➥
else="placeOrder"/>
</decision-state>

<view-state id="enterShippingDetails" view="shippingForm">
<transition on="submit" to="placeOrder">
<action bean="sellItemAction" method="bindAndValidate"/>
</transition>
</view-state>

<action-state id="placeOrder">
<action bean="orderClerk" method="placeOrder(${flowScope.purchase})"/>
<transition on="success" to="showCostConfirmation"/>
</action-state>
<end-state id="showCostConfirmation" view="costConfirmation"/>
<end-state id="cancel" view="home"/>
<import resource="purchase-flow-context.xml"/>
</flow>

The preceding fragment uses the purchasebean, which contains all the shipping informa-
tion as member variables. Since subflows are independent and isolated from their calling flows,
the shipping information will be extracted into its own class called Shipping. This new
Shippingclass will be managed by its own FormAction.
Thus, a new flow (as listed in Listing 12-4) is created in /WEB-INF/flows/shipping-flow.xml.

Listing 12-4.New Spring Web Flow Subflow

<flow start-state="requiresShipping">
<decision-state id="requiresShipping">
<if test="${flowScope.requiresShipping}" then="enterShippingDetails"
else="finish"/>
</decision-state>

338 CHAPTER 12 ■ADVANCED SPRING WEB FLOW

Free download pdf