spring web flow

Spring Web Flow is a web framework for programs where elements run in a prescribed flow. is an extension of spring mvc that supports the development of process-based applications.

 

One: Using web flow in Spring

1: Process executor: Drives the execution of the process. When the user enters a process, the process executor will create and start a process execution instance for the user. When the process is paused, the process executor resumes the process after the user performs an action.

The <flow : flow-executor id = "flowExecutor" flow-registry="flowRegistry" /> element creates a flow executor

 

2: Configure the process registry: Load process definitions and make them available to process executors

<flow : flow-registry id="flowRegistry" base-path = "/WEB-INF/flows">

<flow : flow-location-pattern value = "*-flow.xml"/>

</fow: flow-registry>

 

3: Handle the process request:

(1) FlowHandlerMapping to help DispatcherSerlet send process requests to Spring Web Flow

<bean class = "org.springframework.webflow.mvc.servlet.FlowHandlerMapping">

<property name = "flowRegistry" ref = "flowRegistry">

</bean>

FlowHandlerMapping is equipped with a process registry, and through the process id, it can know that the requested URL matches the process.

 

(2) FlowHandlerAdapter: Equivalent to the controller of Spring mvc. It responds to process requests sent and processes them

<bean class = org.springframework.webflow.mvc.servlet.FlowHandlerAdapter>

<property name = "flowExecutor"  ref = "flowExecutor" />

</bean> 

 

Second, the components of the process:

 

State, by choosing the state of spring web flow, almost any scheduling function can be constructed into a conversational web application.

1: View state, used to present information to the user and use the user to play a role in the process.

<view-state id="welcome" view = "greeting"> is used to define the view state. greeting is the name of the view

If the process presents the form to the user, you may want to specify the object to which the form is bound. 

<view-state id = "takePayment" model = " flowScope.paymentDetail"> Process scope object.

 

2: Behavioral state, which generally triggers some methods of beans managed by Spring and transfers to another state according to the execution result of the method call

<action-state id = saveOrder>

<eval expression = "pizzaFlowActions.saveOrder (order)" />

<transition to = "thankYou" />

</action-state>

 

3: Decision state: It is possible to generate two branches during the execution of the process.

<decision-state id = "checkDeliveryArea">

<if test = "pizzaFlowActions.checkDeliveryArea(customer.zipCode)"

then = "addCustomer" else ="deliveryWarning ">

</decision-state> 

 

4 : Subprocess state: allows calling another process in an executing process

<subflow id = "order"  subflow = "pizza/order">

<input name = "order"  value = "order"/>

<transition on = "orderCreated" to = "payment"> 

</subflow-state>

The <input> element is used to pass the order object as the input to the subprocess. If the <end-state> state id at the end of the sub-process is ordercreated, then the process will transfer to the state named payment

 

5: End state: When the process reaches <end-state>, there may be the following possibilities

1 : If the ending process is a sub-process, the process that called it will continue execution from <subflow-state>.

2: If the <end-state> has the view attribute set, the specified view will be rendered.

3: Not the above two, this process is just over.

 

2. Transfer

Use the <transition> element to define it as a child element of various state elements

<transtion to="customerReady"> to is used to specify the next state of the process.

<transtion on="phoneEntered" to = "lookupCustomer"> on means the event fired

 

Global transitions: After creating a process, you may find that some states use some common transitions. Use <global-transitions>

 

3. Process data: When the process goes from one state to another, it takes away some data.

 Declaring variables Process data is stored in variables, and variables can be referenced anywhere in the process.

1. <var name = "customer" class = "com.springinaction.pizza.domain.Customer" /> This variable can be accessed in the task state of the process.

 

2. <evaluate result = "viewScope.toppingsList" expression = "T(com.springinaction.pizza.domain.Topping).asList()"> Create a variable as part of the behavior state or the entry of the view state indicates that the view scope is

 

3、<set name = "flowScope.pizza" value = "new com.springinaction.pizza.domain.Pizza()">

 

 

 

 

 

 

 

 

 

 

 

 

 

Guess you like

Origin http://10.200.1.11:23101/article/api/json?id=326599206&siteId=291194637