Академический Документы
Профессиональный Документы
Культура Документы
History
Motivation
Positioning
Architecture
Walkthrough
Issues and Solutions
Conclusion
Goals:
Understand Spring’s position in the web
framework space
See the value of Spring Web Flow (SWF) in action
H istory – From Spring’s
Perspective
2000 2003 2004 Fall 2005
Spring AgileDev
(Build, Test, Deploy)
Breakthrough technology
Professional support
Breakthrough Technology
Architecture
By example
Take a simple use case:
A wizard for a phone operator to use to
sell items to customers
Characteristics:
An “application transaction” that spans
several steps
Some steps solicit user input
Some steps are decision points
Some steps perform calculations
Navigation from step-to-step is controlled
H ow w ould you do this today w ith
Struts?
1. Create a session-scoped ActionForm to
hold the wizard form data
2. Define a JSP for each step
3. Define an Action for each step
4. Expose each Action at a request URL
5. Have the form rendered by the JSP
submit to that URL
6. At the end, delegate to a business
service to commit the transaction
W hat this looks like
/step1.do
storeForm
page1
Controller 1 HTTP
Session
/step2.do
updateForm
page2
Controller 2
/lastStep.do Business
processTx Service
confirmationPage
Controller 3
Issues w ith this approach
Request centric: no concept of an ongoing
conversation or flow
Brittle dependency on request URLs
Manual state management
Odd new window behavior
Proper back button behavior is difficult
“Loose” controlled navigation
Difficult to observe process lifecycle
Controller and command logic are coupled
Heavily tied to HTTP
Consequences
Many lines of custom code are
written to address these issues
As an application grows more complex
maintainability breaks down
Fundamentally, something is missing
Traditional approaches today lack a key
abstraction: the Flow
A Flow is typically longer than a single
request but shorter than a session
It is a conversation!
Flow Conversation Analogy
Keith (Oslo, Norway)
Friend: Hello?
Keith: Hi Friend!
Friend: Hi Keith! So, have you
decided to just stay in Europe
for good now?
Keith: Life IS great here, huh?
Friend (Melbourne, Florida)
Keith: Gotta go, bye!
W hat the SW F approach looks
like
start “sell Item”
firstPage
store
submit
Flow
nextPage Execution
Storage
load
submit
end
Active Paused
subflow user input
spawned needed
user event
signaled
Resuming
Q uestion
submit yes
View State
Action State
Show
Decision State Cost Overview
End State
Code Break!
The “Sell Item” Flow Definition
If viewing on-line, see presentation notes
Demo of the Flow Execution
Advantages
The logical flow is clearly defined, readable
Navigation rules are encapsulated in one place
No dependency on any request URLs
Navigation is strictly enforced
State management is automatic
Flow lifecycle is fully observable
Controller logic is clearly decoupled from
command logic
The Flow is the controller, deciding what state to
enter next
States execute arbitrary behavior when entered
HTTP independent
Flow definitions are extremely toolable
W alkthrough: Spring Air
The best way to learn is by example
The airline industry:
Trip booking system
This vertical slice must:
1. Obtain Trip Information
2. Suggest suitable itineraries
3. Assign seats
4. Collect passenger information
5. Book the trip!
Code Break!
The “Booking Agent” business façade
Subsystem boundary
The model context
The façade integration tests
Expressing the booking flow
Building the Booking Flow D efinition
<action-state id="suggestItineraries">
<action bean=“bookingActions"/>
<transition on="success“ to="displaySuggestedItineraries"/>
</action-state>
<view-state id="displaySuggestedItineraries"
view="suggestedItineraries">
<transition on="startOver" to="cancel"/>
<transition on="select" to=“recordSelectedItinerary"/>
</view-state>
<action-state id=“recordSelectedItinerary">
<action bean=“bookingActions"/>
<transition on="success" to="isPassengerInfoRequired"/>
</action-state>
The flow pauses while the view is displayed for user “think time”
The flow resumes in the same state on the next request (“post
back”) to decide where to go next
D eciding w here to go next
Is passenger information required? If so, enter it. If
not, go straight to verification
<action-state id=“isPassengerInfoRequired”>
<transition on=“yes” to=“enterPassengerInformation”/>
<transition on=“no” to=“displayReservationVerification”/>
</action-state>
<subflow-state id="enterPassengerInformation"
flow="passenger">
<attribute-mapper>
<input value="${requestScope.passenger.id}“ as=“id”/>
</attribute-mapper>
<transition on="finish" to="displayReservationVerification"/>
</subflow-state>
<view-state id="displayReservationVerification"
view="reservationVerification">
<transition on="startOver" to="cancel"/>
<transition on="assignSeats" to="chooseSeatAssignments"/>
<transition on="book" to="book"/>
</view-state>
<action-state id="book">
<action bean=“bookingFlowActions"/>
<transition on="success" to="displayConfirmation"/>
</action-state>
<bean id="booking“
class="org.springframework.web.flow.config.XmlFlowFactoryBean">
<property name="location“ value="classpath:/flows/booking.xml"/>
</bean>
Using an anchor:
<a href="<c:url
value="/springair.htm?_flowId=booking&src.airport=MLB&
dest.airport=ATL"/>">
Launch Booking Flow
</a>
Exam ples: view s participating in
flow s
Using a form:
Using an anchor:
<a href="<c:url
value="/springair.htm?_flowExecutionId=${flowExecutionId}
& _eventId=submit&firstName=Keri&lastName=Donald/>“>Enter
Passenger Information</a>
Example:
<action-state=“book”>
<property name=“role” value=“passenger”
type=“grantedAuthority”/>
<action bean=“bookingAction”>
<property name=“caption” value=“Books the
reservation”/>
</action>
</action-state>
Issues and Solutions
Integrating into other environments
Create a specialized FlowController for that
environment
For example:
• The FlowAction for Struts
• The FlowNavigationHandler for JSF
• The PortletFlowController for Portlets
Spring Web Flow is not coupled with any other
web framework
Not even Spring MVC or the Servlet API
Menus