SPRING IN ACTION 第4版笔记-第八章Advanced Spring MVC-005-Pizza例子的订单流程()
2016-03-06 21:08
691 查看
一、
![](http://images2015.cnblogs.com/blog/653056/201603/653056-20160306205824627-724554687.png)
1.订单流程定义文件order-flow.xml
或者
The <on-entry> element adds a new Pizza object to flow scope to be populated when the form is submitted. Note that the model of this view state references the same flow-scoped Pizza object. That Pizza object is bound to the Create Pizza form, shown next.
2.createPizza.jsp
When the form is submitted via the Continue button, the size and topping selections are bound to the Pizza object, and the addPizza transition is taken. The <evaluate> element associated with that transition indicates that the flow-scoped Pizza object should be passed in a call to the order’s addPizza() method before transitioning to the showOrder state.
![](http://images2015.cnblogs.com/blog/653056/201603/653056-20160306205824627-724554687.png)
1.订单流程定义文件order-flow.xml
<?xml version="1.0" encoding="UTF-8"?> <flow xmlns="http://www.springframework.org/schema/webflow" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" Listing 8.8 Order subflow view shows states to display the order and create a pizza create Pizza S Start cancel order Created createPizza cancel/addPizza checkout cancel showOrder Figure 8.4 Pizzas are added via the order subflow. www.it-ebooks.info 239 Putting it all together: the pizza flow xsi:schemaLocation="http://www.springframework.org/schema/webflow http://www.springframework.org/schema/webflow/spring-webflow-2.3.xsd"> <input name="order" required="true" /> <view-state id="showOrder"> <transition on="createPizza" to="createPizza" /> <transition on="checkout" to="orderCreated" /> <transition on="cancel" to="cancel" /> </view-state> <view- state id="createPizza" model="flowScope.pizza"> <on-entry> <set name="flowScope.pizza" value="new com.springinaction.pizza.domain.Pizza()" /> <evaluate result="viewScope.toppingsList" expression="T(com.springinaction.pizza.domain.Topping).asList()" /> </on-entry> <transition on="addPizza" to="showOrder"> <evaluate expression="order.addPizza(flowScope.pizza)" /> </transition> <transition on="cancel" to="showOrder" /> </view-state> <end-state id="cancel" / <end-state id="orderCreated" /> </flow>
或者
<?xml version="1.0" encoding="UTF-8"?> <flow xmlns="http://www.springframework.org/schema/webflow" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://www.springframework.org/schema/webflow http://www.springframework.org/schema/webflow/spring-webflow-2.0.xsd"> <input name="order" required="true" /> <!-- Order --> <view-state id="showOrder"> <transition on="createPizza" to="createPizza" /> <transition on="checkout" to="orderCreated" /> <transition on="cancel" to="cancel" /> </view-state> <view-state id="createPizza" model="flowScope.pizza"> <on-entry> <set name="flowScope.pizza" value="new com.springinaction.pizza.domain.Pizza()" /> <evaluate result="viewScope.toppingsList" expression="T(com.springinaction.pizza.domain.Topping).asList()" /> </on-entry> <transition on="addPizza" to="showOrder"> <evaluate expression="order.addPizza(flowScope.pizza)" /> </transition> <transition on="cancel" to="showOrder" /> </view-state> <!-- End state --> <end-state id="cancel" /> <end-state id="orderCreated" /> </flow>
The <on-entry> element adds a new Pizza object to flow scope to be populated when the form is submitted. Note that the model of this view state references the same flow-scoped Pizza object. That Pizza object is bound to the Create Pizza form, shown next.
2.createPizza.jsp
<%@ taglib prefix="form" uri="http://www.springframework.org/tags/form" %> <div> <h2>Create Pizza</h2> <form:form commandName="pizza"> <input type="hidden" name="_flowExecutionKey" value="${flowExecutionKey}"/> <b>Size: </b><br/> <form:radiobutton path="size" label="Small (12-inch)" value="SMALL"/><br/> <form:radiobutton path="size" label="Medium (14-inch)" value="MEDIUM"/><br/> <form:radiobutton path="size" label="Large (16-inch)" value="LARGE"/><br/> <form:radiobutton path="size" label="Ginormous (20-inch)" value="GINORMOUS"/><br/> <br/> <b>Toppings: </b><br/> <form:checkboxes path="toppings" items="${toppingsList}" delimiter="<br/>"/><br/><br/> <input type="submit" class="button" name="_eventId_addPizza" value="Continue"/> <input type="submit" class="button" name="_eventId_cancel" value="Cancel"/> </form:form> </div>
When the form is submitted via the Continue button, the size and topping selections are bound to the Pizza object, and the addPizza transition is taken. The <evaluate> element associated with that transition indicates that the flow-scoped Pizza object should be passed in a call to the order’s addPizza() method before transitioning to the showOrder state.
相关文章推荐
- 秒懂java回调方法
- 20145225唐振远 《Java程序设计》第1周学习总结——小试牛刀
- Java基本数据类型数组与可变长度参数
- java中常用的工具类(三)
- java并发编程中CountDownLatch和CyclicBarrier和Semaphore的使用
- java中常用的工具类(二)
- 20145235李涛《Java程序设计》第一周学习总结
- spring学习整理
- SPRING IN ACTION 第4版笔记-第八章Advanced Spring MVC-004-Pizza例子的用户流程(flowExecutionKey、_eventId_phoneEntered、flowExecutionUrl )
- 20145315 《Java程序设计》第一周学习总结
- 重读Java,争取到skilled & Core Java V1,10th第三章笔记
- 【JAVA】30、类与对象的关系
- Spring MVC入门实战(一)
- Core Java (七) Java中的static修饰符
- java-swing-皮肤
- Spring Profile基本使用
- Java中equals、==、hashcode的区别
- (java) Kth Smallest Element in a BST
- 【java学习记录】spilt小结
- Java [Leetcode 268]Missing Number