From fd4cd03c9ef55069cd6076b8377f90bd180764c8 Mon Sep 17 00:00:00 2001 From: Keith Donald Date: Mon, 7 Apr 2008 03:08:54 +0000 Subject: [PATCH] doc updates --- .../src/defining-flows.xml | 148 ++++++++++++++++-- 1 file changed, 136 insertions(+), 12 deletions(-) diff --git a/spring-webflow-reference/src/defining-flows.xml b/spring-webflow-reference/src/defining-flows.xml index dfbc0466..63122855 100644 --- a/spring-webflow-reference/src/defining-flows.xml +++ b/spring-webflow-reference/src/defining-flows.xml @@ -99,7 +99,6 @@ <view-state id="enterBookingDetails"> <transition on="submit" to="reviewBooking" /> - <transition on="cancel" to="bookingCancelled" /> </view-state> @@ -133,7 +132,6 @@ <view-state id="enterBookingDetails"> <transition on="submit" to="reviewBooking" /> - <transition on="cancel" to="bookingCancelled" /> </view-state> <view-state id="reviewBooking"> @@ -259,7 +257,6 @@ <view-state id="enterBookingDetails"> <transition on="submit" to="reviewBooking" /> - <transition on="cancel" to="bookingCancelled" /> </view-state> <view-state id="reviewBooking"> @@ -349,7 +346,7 @@ public interface FlowOutcome { Output attributes are declared within end-states that represent specific flow outcomes. -<end-state> id="bookingConfirmed"; +<end-state id="bookingConfirmed"> <output name="bookingId" /> </end-state> @@ -365,27 +362,154 @@ public interface FlowOutcome { <output name="confirmationNumber" value="booking.confirmationNumber" /> - + + + Checkpoint: input/output mapping + + Now review the sample booking flow with input/output mapping: + + +<flow xmlns="http://www.springframework.org/schema/webflow" + xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" + xsi:schemaLocation="http://www.springframework.org/schema/webflow + http://www.springframework.org/schema/webflow/spring-webflow-2.0.xsd"> + + <input name="hotelId" /> + + <on-start> + <evaluate expression="bookingService.createBooking(hotelId, currentUser.name)" result="flowScope.booking" /> + </on-start> + + <view-state id="enterBookingDetails"> + <transition on="submit" to="reviewBooking" /> + </view-state> + + <view-state id="reviewBooking"> + <transition on="confirm" to="bookingConfirmed" /> + <transition on="revise" to="enterBookingDetails" /> + <transition on="cancel" to="bookingCancelled" /> + </view-state> + + <end-state id="bookingConfirmed" > + <output name="bookingId" value="booking.id"/> + </end-state> + + <end-state id="bookingCancelled" /> + +</flow> + + + + + Variables + + A flow may declare one or more instance variables. + These variables are allocated when the flow starts. + Any @Autowired transient references the variable holds are also rewired when the flow resumes. + + + Use the var element to declare a flow variable: + + +<var name="searchCriteria" class="com.mycompany.myapp.hotels.search.SearchCriteria"/> + + + Make sure your variable's class implements java.io.Serializable, as the instance state is saved between flow requests. + Calling subflows - A flow may call another flow as a subflow. The flow will wait until the subflow returns before responding to its outcome. + A flow may call another flow as a subflow. The flow will wait until the subflow returns, then respond to the subflow outcome. The subflow-state element - Use the subflow-state element to call another flow: + Use the subflow-state element to call another flow as a subflow: -<subflow-state id="addGuest"> - <transition on="guestAdded" to="reviewBooking" > - <evaluate expression="booking.guests.add(guest)"/> +<subflow-state id="addGuest" subflow="createGuest"> + <transition on="guestCreated" to="reviewBooking"> + <evaluate expression="booking.guests.add(guest)"/> <transition /> - <transition on="cancel" to="reviewBooking" /> + <transition on="creationCancelled" to="reviewBooking" /> </subfow-state> - + + + The above example calls the createGuest flow, then waits for it to return. + When the flow returns with a guestCreated outcome, the new guest is added to the booking's guest list. + + + Passing a subflow input + + Use the input element to pass input to the subflow: + + +<subflow-state id="addGuest" subflow="createGuest"> + <input name="booking" /> + <transition to="reviewBooking" /> +</subfow-state> + + + + Mapping subflow output + + Simply refer to a subflow output attribute by its name within a outcome transition: + + +<transition on="guestCreated" to="reviewBooking"> + <evaluate expression="booking.guests.add(guest)"/> +<transition /> + + + In the above example, guest is the name of an output attribute returned by the guestCreated outcome. + + + + Checkpoint: calling subflows + + Now review the sample booking flow calling a subflow: + + +<flow xmlns="http://www.springframework.org/schema/webflow" + xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" + xsi:schemaLocation="http://www.springframework.org/schema/webflow + http://www.springframework.org/schema/webflow/spring-webflow-2.0.xsd"> + + <input name="hotelId" /> + + <on-start> + <evaluate expression="bookingService.createBooking(hotelId, currentUser.name)" result="flowScope.booking" /> + </on-start> + + <view-state id="enterBookingDetails"> + <transition on="submit" to="reviewBooking" /> + </view-state> + + <view-state id="reviewBooking"> + <transition on="addGuest" to="addGuest" /> + <transition on="confirm" to="bookingConfirmed" /> + <transition on="revise" to="enterBookingDetails" /> + <transition on="cancel" to="bookingCancelled" /> + </view-state> + + <subflow-state id="addGuest" subflow="createGuest"> + <transition on="guestCreated" to="reviewBooking"> + <evaluate expression="booking.guests.add(guest)"/> + <transition /> + <transition on="creationCancelled" to="reviewBooking" /> + </subfow-state> + + <end-state id="bookingConfirmed" > + <output name="bookingId" value="booking.id"/> + </end-state> + + <end-state id="bookingCancelled" /> + +</flow> + + Transitions without target states