Expert Spring MVC and Web Flow

(Dana P.) #1

The Purchase Product Flow Definition


A flow definition can be engineered in a number of ways. Many users use XML to define their
flows, as XML is a human readable and highly toolable format. However, you may also define
flows in Java (by extending AbstractFlowBuilder) or with your own custom format by imple-
menting a custom FlowBuilder.
For the Purchase Product example web flow, you will use XML. Recall the graphical depic-
tion of the flow definition in Figure 11-4.

Implementing the First Step: View States


The first step of this flow is to enter the purchase information, which requires the user to par-
ticipate in the flow by providing the following bits of information:


  • The price at which the product should be sold

  • The quantity of products that are to be sold for this order


Since this is the first step of the flow, it is designated as the start state. Since it is a step
where the user is involved, it is a view state. A view state will select a view to render to allow
the user to participate in the flow. See Listing 11-1.

Listing 11-1./WEB-INF/flows/purchase-flow.xml

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE flow PUBLIC "-//SPRING//DTD WEBFLOW 1.0//EN"
"http://www.springframework.org/dtd/spring-webflow-1.0.dtd">

<flow start-state="enterPurchaseInformation">
<view-state id="enterPurchaseInformation" view="purchaseForm">

</view-state>
</flow>

The preceding instruction means, “When an execution of this flow starts, enter the
enterPurchaseInformationstate. Then select the purchaseFormview for display to the user, and
pause the flow execution until a user event is signaled.”

Transitions


As it stands, the preceding view-state definition is incomplete. Recall that all transitionable
state types, which include the view state, must define at least one transition that leads to
another state.
Also recall that a transition is triggered by the occurrence of an event. A view-state event
is triggered by the user to communicate what action the user took. For example, the user may
press the “submit” or “cancel” button. So for a view state, the set of transitions define the sup-
ported user events you wish to respond to for that state and how you wish to respond to them,
as defined in Listing 11-2.

320 CHAPTER 11 ■INTRODUCTION TO SPRING WEB FLOW

Free download pdf