Expert Spring MVC and Web Flow

(Dana P.) #1
<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>
<import resource=”purchase-flow-context.xml”/>
</flow>

In this case the action referenced is the orderClerk, which is simply a plain old Java object
(POJO). The referenced OrderClerkimplementation has no dependency on SWF and does not
implement the Actioninterface—Spring Web Flow will adapt the placeOrder method to the
Actioninterface automatically. As you can see, method argument expressions can also be
specified.
The preceding action-state definition means, “When the placeOrderstate is entered,
invoke the placeOrder()method on the orderClerkfaçade, passing it the purchaseobject from
flow scopeas an input argument; then, on a successful return (when no exception is thrown)
transition to the showCostConfirmationstate.”
Action states are not limited to invoking just one action; you may invoke any number of
actions as part of a chain. You will see how and when to do this in Chapter 12.

■NoteYou’ll learn more about Chain of Responsibility and Spring’s POJO-method-binding capability in
Chapter 12.

End States


The last core state type needed to complete the example flow is the end state. End states sim-
ply terminate the executing flow when entered. Once the execution of a flow is terminated,
any allocated resources in flow scope are automatically cleaned up. The execution cannot
“come back;” it is only possible to start a new, completely independent execution.

■NoteThe exception to this is if the ending flow is being used as a subflow, in which case the flow that
spawned the subflow is expected to resume execution. For more information on subflows, consult Chapter 12.

328 CHAPTER 11 ■INTRODUCTION TO SPRING WEB FLOW

Free download pdf