introduction to srping web flow
TRANSCRIPT
1
IntroducingSpring Web Flow
Emad OmaraMay 30, 2016
2
Agenda• Why do we need SWF ?• What is SWF ?• How it works ?• Demo
3
The Navigation problem ! response.sendRedirect(“page.jsp");
Spring MVC : @RequestMapping("/operation") public String processOperationPage() { return “/corpus/operation"; }
- Struts<action-mappings> …. <forward name="name" path="/name.jsp"/> </ action-mappings>
- JSF <navigation-rule><navigation-case> <from-outcome>page2</from-outcome> <to-view-id>/page2.xhtml</to-view-id> </navigation-case> </navigation-rule>
4
Disadvantages
Visualizing the flow is very difficult Mixed navigation and view Overall navigation rules complexity Lack of state control/navigation customization
5
What is Spring Web Flow?
Spring MVC extension Introduces flows conceptExtends application scopesWeb flows are designed to be self contained, and
thus are reusable multiple of timesUML Like diagram
6
Important Classes FlowDefinition - This class stores the definition of the flow. It contains the set of states that
form part of the flow. Each flow has one start state. FlowRegistry - This class contains all the flow definitions. FlowHandlerMapping - This is a HandlerMapping that creates a URL from the ids registered
in the flow registry. It returns a FlowHandler if a matching id is found in the flow registry. FlowHandler - This is a controller helper that has the reference to the actual flow. It
handles the execution of the flow, its outcomes and exceptions. FlowHandlerAdapter - This is the HandlerAdapter for web flows. It delegates work to the
mapped FlowHandler. FlowExecutor - This is the central class of the Flow and is the facade for the actual flow. It
manages creating of new flows or resuming existing flows. It is an entry into the Spring web flow system.
Request Diagram
8
System Setup Web Flow schema :
<beans xmlns="http://www.springframework.org/schema/beans" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:webflow="http://www.springframework.org/schema/webflow-config" xsi:schemaLocation=" http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-4.0.xsd http://www.springframework.org/schema/webflow-config http://www.springframework.org/schema/webflow-config/spring-webflow-config-2.4.xsd"> <!-- Setup Web Flow here -->
</beans>
9
System Setup 2 (Flow Registry)URL : /WEB-INF/flows/hotels/booking/booking-flow.xml
Flow ID=/hotels/booking
Flow ID=springpizza
Flow ID=pizza
10
System Setup 3
11
Flow A flow defines a dialogue, between users and server that meets business goal
12
Flow Essential elements State Transition Flow data Expression language
13
Flow States View States : A view state displays information to a user or obtains user input
using a form. (e.g. JSP) Action States : Action states are where actions are perfomed by the spring
beans. The action state transitions to another state. The action states generally have an evaluate property that describes what needs to be done.
Decision States: A decision state has two transitions depending on whether the decision evaluates to true or false.
Subflow States :It may be advantageous to call another flow from one flow to complete some steps. Passing inputs and expecting outputs.
End States : The end state signifies the end of flow. If the end state is part of a root flow then the execution is ended. However, if its part of a sub flow then the root flow is resumed.
14
Flow Data Scopes Flow Data can be stored as variables that can be created using the 'var' element. Variable scope - The lifespan of the variable depends on the scope with which it is
declared. The scopes available are: Request - Available during the life of a request in a flow Flash -Extended request scope for PRG case , Useful for rendering error/warning messages View - Available only during the lifetime of a view. Created when a view is created and destroyed
once a view is destroyed Flow - Available within a flow. Not available in sub flows Conversation - The conversation scope starts when a flow starts and ends when the flow ends. It
is available in sub flows
15
Flow elements
16
View State
17
Decision State
18
Action State
19
Sub Flow State
20
Input attributes
21
Output Value
22
Firing Events
23
Events
24
References
Web Flow reference http://static.springframework.org/spring-webflow/docs/2.3.x/reference/html/index.html
samples https://github.com/spring-projects/spring-webflow-samples
Spring Web Flow 2 Web Development https://www.safaribooksonline.com/library/view/spring-web-flow/9781847195425/pr01.html
Refcardz http://refcardz.dzone.com/refcardz/spring-web-flow
25
Demo
26
Thank youEmad