introduction to srping web flow

26
Introducing Spring Web Flow Emad Omara 1 May 30, 2016

Upload: emad-omara

Post on 17-Feb-2017

130 views

Category:

Technology


3 download

TRANSCRIPT

Page 1: Introduction to Srping Web Flow

1

IntroducingSpring Web Flow

Emad OmaraMay 30, 2016

Page 2: Introduction to Srping Web Flow

2

Agenda• Why do we need SWF ?• What is SWF ?• How it works ?• Demo

Page 3: Introduction to Srping Web Flow

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>

Page 4: Introduction to Srping Web Flow

4

Disadvantages

Visualizing the flow is very difficult Mixed navigation and view Overall navigation rules complexity Lack of state control/navigation customization

Page 5: Introduction to Srping Web Flow

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

Page 6: Introduction to Srping Web Flow

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.

Page 7: Introduction to Srping Web Flow

Request Diagram

Page 8: Introduction to Srping Web Flow

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>

Page 9: Introduction to Srping Web Flow

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

Page 10: Introduction to Srping Web Flow

10

System Setup 3

Page 11: Introduction to Srping Web Flow

11

Flow A flow defines a dialogue, between users and server that meets business goal

Page 12: Introduction to Srping Web Flow

12

Flow Essential elements State Transition Flow data Expression language

Page 13: Introduction to Srping Web Flow

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.

Page 14: Introduction to Srping Web Flow

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

Page 15: Introduction to Srping Web Flow

15

Flow elements

Page 16: Introduction to Srping Web Flow

16

View State

Page 17: Introduction to Srping Web Flow

17

Decision State

Page 18: Introduction to Srping Web Flow

18

Action State

Page 19: Introduction to Srping Web Flow

19

Sub Flow State

Page 20: Introduction to Srping Web Flow

20

Input attributes

Page 21: Introduction to Srping Web Flow

21

Output Value

Page 22: Introduction to Srping Web Flow

22

Firing Events

Page 23: Introduction to Srping Web Flow

23

Events

Page 24: Introduction to Srping Web Flow

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

Page 25: Introduction to Srping Web Flow

25

Demo

Page 26: Introduction to Srping Web Flow

26

Thank youEmad