
正文
SPRING IN ACTION 第4版笔记-第八章Advanced Spring MVC-002-SpringFlow的组件(state\<transition>\<var>\<set>\<evaluate>)
提示:扫一扫查出行【扫一扫了解最新限行尾号】
复制提示
一、
In Spring Web Flow, a flow is defined by three primary elements: states, transitions,and flow data.如果把webflow当做是一次旅行,则state是旅途中每个景点,而transitions是连接景点的路径,data是在每个景点中购买的纪念品。
1.state
(1)支持的状态
(2)view-state
View states are used to display information to the user and to offer the user an opportunity to play an active role in the flow. The actual view implementation could be any of the views supported by Spring MVC but is often implemented in JSP .
<view-state id="welcome" />
因为没有指定view,所以对应的view以id为准,即welcome.jsp。也可明确指定view
<view-state id="welcome" view="greeting" />
If a flow presents a form to the user, you may want to specify the object to which the form will be bound. To do that, set the model attribute:
<view-state id="takePayment" model="flowScope.paymentDetails"/>
Here you specify that the form in the takePayment view will be bound to the flowscoped paymentDetails object.
(3)action-state
Whereas view states involve the users of the application in the flow, action states are where the application itself goes to work. Action states typically invoke some method on a Spring-managed bean and then transition to another state depending on the outcome of the method call.
<action-state id="saveOrder">
<evaluate expression="pizzaFlowActions.saveOrder(order)" />
<transition to="thankYou" />
</action-state>
The <evaluate> element gives an action state something to do. The expression attribute is given an expression that’s evaluated when the state is entered. In this case, expression is given a SpEL expression indicating that the
saveOrder() method should be called on a bean whose ID is pizzaFlowActions
(4)DECISION STATES
Decision states enable a binary branch in a flow execution. A decision state evaluates a Boolean expression and takes one of two transitions, depending on whether the expression evaluates to true or false .
<decision-state id="checkDeliveryArea">
<if test="pizzaFlowActions.checkDeliveryArea(customer.zipCode)" then="addCustomer"
else="deliveryWarning" />
</decision-state>
(5)SUBFLOW STATES
在一个应用中,你不会把所有逻辑都写到一个方法里,你会拆分,SUBFLOW STATES就像是在一个方法里调用另一个方法来完成任务。
The<subflow-state> element lets you call another flow from within an executing flow.
<!-- Order -->
<subflow-state id="order" subflow="pizza/order">
<input name="order" value="order"/>
<transition on="orderCreated" to="payment" />
</subflow-state>
Here, the <input> element is used to pass the order object as input to the subflow.And if the subflow ends with an <end-state> whose ID is orderCreated , then the flow will transition to the state whose ID is payment
(6)END STATES
<end-state id="customerReady" />
When the flow reaches an <end-state> , the flow ends. What happens next depends on a few factors:
If the flow that’s ending is a subflow, the calling flow will proceed from the <subflow-state> . The <end-state> ’s ID will be used as an event to trigger the transition away from the <subflow-state> .
If the <end-state> has its view attribute set, the specified view will be rendered.The view may be a flow-relative path to a view template, prefixed withexternalRedirect: to redirect to some page external to the flow, or prefixed
with flowRedirect: to redirect to another flow.
If the ending flow isn’t a subflow and no view is specified, the flow ends. The browser lands on the flow’s base URL , and, with no current flow active, a new instance of the flow begins.
2.transitions
transitions connect the states within a flow. Every state in a flow, with the exception of end states, should have at least one transition so that the flow will know where to go once that state has completed
<transition to="customerReady" />
The to attribute is used to specify the next state in the flow. When <transition> is declared with only a to attribute, the transition is the default transition for that state and will be taken if no other transitions are applicable.
More commonly, transitions are defined to take place on some event being fired.In a view state, the event is usually an action taken by the user. In an action state, theevent is the result of evaluating an expression. In the case of a subflow state, the eventis determined by the ID of the subflow’s end state. In any event (no pun intended),you can specify the event to trigger the transition in the on attribute:
<transition on="phoneEntered" to="lookupCustomer"/>
In this example, the flow will transition to the state whose ID is lookupCustomer if a phoneEntered event is fired.
The flow can also transition to another state in response to some exception being thrown.
<transition
on-exception="com.springinaction.pizza.service.CustomerNotFoundException" to="registrationForm" />
The on-exception attribute is much like the on attribute, except that it specifies an exception to transition on instead of an event.
(2)GLOBAL TRANSITIONS
<global-transitions>
<transition on="cancel" to="endState" />
</global-transitions>
With this global transition in place, all states in the flow will have an implicit cancel transition.
3.flow data
(1)<var>
<var name="customer" class="com.springinaction.pizza.domain.Customer"/>
a new instance of a Customer object is created and placed into the variable whose name is customer . This variable is available to all states in a flow.
(2)<evaluate>
As part of an action state or on entry to a view state, you may also create variables using the <evaluate> element. For example,
<evaluate result="viewScope.toppingsList" expression="T(com.springinaction.pizza.domain.Topping).asList()" />
In this case, the <evaluate> element evaluates an expression (a SpEL expression) and places the result in a variable named toppingsList that’s view-scoped.
(3)<set>
<set name="flowScope.pizza" value="new com.springinaction.pizza.domain.Pizza()" />
The <set> element works much the same as the <evaluate> element, setting a vari able to the resulting value from an evaluated expression. Here, you’re setting a flow- scoped pizza variable to a new instance of a Pizza object.
4.scope
When you declare a variable using the <var> element, the variable is always flow-scoped in the flow defining the variable. When you use <set> or <evaluate> , the scope is specified as a prefix for the name or result attribute. For example, here’s how you would assign a value to a flow-scoped variable named theAnswer :
<set name="flowScope.theAnswer" value="42"/>
SPRING IN ACTION 第4版笔记-第八章Advanced Spring MVC-002-SpringFlow的组件(state\<transition>\<var>\<set>\<evaluate>)的更多相关文章
-
SPRING IN ACTION 第4版笔记-第八章Advanced Spring MVC-007-给flowl加权限控制<secured>
States, transitions, and entire flows can be secured in Spring Web Flow by using the <secured> ...
-
SPRING IN ACTION 第4版笔记-第八章Advanced Spring MVC-004-Pizza例子的用户流程(flowExecutionKey、_eventId_phoneEntered、flowExecutionUrl )
一. 1. 2. 3.customer-flow.xml 自己定义customer,最后output <?xml version="1.0" encoding="U ...
-
SPRING IN ACTION 第4版笔记-第八章Advanced Spring MVC-003-Pizza例子的基本流程
一. 1. 2.pizza-flow.xml <?xml version="1.0" encoding="UTF-8"?> <flow xml ...
-
SPRING IN ACTION 第4版笔记-第八章Advanced Spring MVC-001- 配置SpringFlow(flow-executor、flow-registry、FlowHandlerMapping、FlowHandlerAdapter)
一. 1.Wiring a flow executor <flow:flow-executor id="flowExecutor" /> Although the fl ...
-
SPRING IN ACTION 第4版笔记-第八章Advanced Spring MVC-006-Pizza例子的支付流程
一. 1. 2.payment-flow.xml <?xml version="1.0" encoding="UTF-8"?> <flow x ...
-
SPRING IN ACTION 第4版笔记-第八章Advanced Spring MVC-005-Pizza例子的订单流程()
一. 1.订单流程定义文件order-flow.xml <?xml version="1.0" encoding="UTF-8"?> <flo ...
-
SPRING IN ACTION 第4版笔记-第十一章Persisting data with object-relational mapping-006Spring-Data的运行规则(@EnableJpaRepositories、<jpa:repositories>)
一.JpaRepository 1.要使Spring自动生成实现类的步骤 (1)配置文件xml <?xml version="1.0" encoding="UTF- ...
-
SPRING IN ACTION 第4版笔记-第十章Hitting the database with spring and jdbc-003-四种方式获取DataSource
一.概述 1.Spring offers several options for configuring data-source beans in your Spring application, i ...
-
SPRING IN ACTION 第4版笔记-第十章Hitting the database with spring and jdbc-001-Spring对原始JDBC的封装
1.spring扩展的jdbc异常 2.Template的运行机制 Spring separates the fixed and variable parts of the data-access p ...
随机推荐
-
Android沉浸式状态栏实现
Step1:状态栏与导航栏半透明化 方法一:继承主题特定主题 在Android API 19以上可以使用****.TranslucentDecor***有关的主题,自带相应半透明效果 例如: < ...
-
Asp.Net Cookie的清除
背景 最近做到一个asp.net项目,项目中保存用户信息用到了cookie,因此,在注销身份的时候,就需要清除掉cookie. 探索过程 我先是试验了这种代码,在没有特殊声明前,代码都是写在Page_ ...
-
myeclipse 右键 Add Struts... 页面报404 错误
网上试了很多种方法都不对,结果老师两下点出来了 我的改正方法是: 将WebRoot/WEB-INF/web.xml中的 <url-pattern>/*</url-pattern> ...
-
(poj)1806 Currency Exchange
题目链接:http://poj.org/problem?id=1860 Description Several currency exchange points are working in our ...
-
MFC: Create Directory
Original link: How to check if Directory already Exists in MFC(VC++)? MSDN Links: CreateDirectory fu ...
-
hdu 5056 Boring count
贪心算法.需要计算分别以每个字母结尾的且每个字母出现的次数不超过k的字符串,我们设定一个初始位置s,然后用游标i从头到尾遍历字符串,使用map记录期间各个字母出现的次数,如果以s开头i结尾的字符串满足 ...
-
rsync+inotity
rsync默认端口:873xinetd默认服务 inotify参数详解inotifywait-r:递归-q:只打印事件-m:始终监听事件--excludei:排除--timefmt:时间格式--for ...
-
排序算法FIVE:插入排序InsertSort
/** *插入排序思路:O(n^2) * 最外层一个循环,从第二个数到最后一个,变量为i * 每个数存储在key变量中 * 变量j,是左边已经排好序的数组的上限 * 判断key与前面每一个数比较 1, ...
-
对WebClient扩展自动解压缩页面
WebClient下载压缩网页时出现的全是乱码,可通过扩展来解决这个问题. public class MyWebClient : WebClient { protected override WebR ...
-
JS 页面打印
var hkey_root, hkey_path, hkey_key hkey_root = "HKEY_CURRENT_USER" hkey_path = "\\Sof ...
States, transitions, and entire flows can be secured in Spring Web Flow by using the <secured> ...
一. 1. 2. 3.customer-flow.xml 自己定义customer,最后output <?xml version="1.0" encoding="U ...
一. 1. 2.pizza-flow.xml <?xml version="1.0" encoding="UTF-8"?> <flow xml ...
一. 1.Wiring a flow executor <flow:flow-executor id="flowExecutor" /> Although the fl ...
一. 1. 2.payment-flow.xml <?xml version="1.0" encoding="UTF-8"?> <flow x ...
一. 1.订单流程定义文件order-flow.xml <?xml version="1.0" encoding="UTF-8"?> <flo ...
一.JpaRepository 1.要使Spring自动生成实现类的步骤 (1)配置文件xml <?xml version="1.0" encoding="UTF- ...
一.概述 1.Spring offers several options for configuring data-source beans in your Spring application, i ...
1.spring扩展的jdbc异常 2.Template的运行机制 Spring separates the fixed and variable parts of the data-access p ...
-
Android沉浸式状态栏实现
Step1:状态栏与导航栏半透明化 方法一:继承主题特定主题 在Android API 19以上可以使用****.TranslucentDecor***有关的主题,自带相应半透明效果 例如: < ...
-
Asp.Net Cookie的清除
背景 最近做到一个asp.net项目,项目中保存用户信息用到了cookie,因此,在注销身份的时候,就需要清除掉cookie. 探索过程 我先是试验了这种代码,在没有特殊声明前,代码都是写在Page_ ...
-
myeclipse 右键 Add Struts... 页面报404 错误
网上试了很多种方法都不对,结果老师两下点出来了 我的改正方法是: 将WebRoot/WEB-INF/web.xml中的 <url-pattern>/*</url-pattern> ...
-
(poj)1806 Currency Exchange
题目链接:http://poj.org/problem?id=1860 Description Several currency exchange points are working in our ...
-
MFC: Create Directory
Original link: How to check if Directory already Exists in MFC(VC++)? MSDN Links: CreateDirectory fu ...
-
hdu 5056 Boring count
贪心算法.需要计算分别以每个字母结尾的且每个字母出现的次数不超过k的字符串,我们设定一个初始位置s,然后用游标i从头到尾遍历字符串,使用map记录期间各个字母出现的次数,如果以s开头i结尾的字符串满足 ...
-
rsync+inotity
rsync默认端口:873xinetd默认服务 inotify参数详解inotifywait-r:递归-q:只打印事件-m:始终监听事件--excludei:排除--timefmt:时间格式--for ...
-
排序算法FIVE:插入排序InsertSort
/** *插入排序思路:O(n^2) * 最外层一个循环,从第二个数到最后一个,变量为i * 每个数存储在key变量中 * 变量j,是左边已经排好序的数组的上限 * 判断key与前面每一个数比较 1, ...
-
对WebClient扩展自动解压缩页面
WebClient下载压缩网页时出现的全是乱码,可通过扩展来解决这个问题. public class MyWebClient : WebClient { protected override WebR ...
-
JS 页面打印
var hkey_root, hkey_path, hkey_key hkey_root = "HKEY_CURRENT_USER" hkey_path = "\\Sof ...







