SPRING IN ACTION 第4版笔记-第八章Advanced Spring MVC-005-Pizza例子的订单流程()

时间:2022-04-07 22:50:59

一、

SPRING IN ACTION 第4版笔记-第八章Advanced Spring MVC-005-Pizza例子的订单流程()

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.

SPRING IN ACTION 第4版笔记-第八章Advanced Spring MVC-005-Pizza例子的订单流程()的更多相关文章

  1. SPRING IN ACTION 第4版笔记-第八章Advanced Spring MVC-004-Pizza例子的用户流程&lpar;flowExecutionKey、&lowbar;eventId&lowbar;phoneEntered、flowExecutionUrl &rpar;

    一. 1. 2. 3.customer-flow.xml 自己定义customer,最后output <?xml version="1.0" encoding="U ...

  2. SPRING IN ACTION 第4版笔记-第八章Advanced Spring MVC-003-Pizza例子的基本流程

    一. 1. 2.pizza-flow.xml <?xml version="1.0" encoding="UTF-8"?> <flow xml ...

  3. SPRING IN ACTION 第4版笔记-第八章Advanced Spring MVC-002-SpringFlow的组件&lpar;state&bsol;&lt&semi;transition&gt&semi;&bsol;&lt&semi;var&gt&semi;&bsol;&lt&semi;set&gt&semi;&bsol;&lt&semi;evaluate&gt&semi;&rpar;

    一. In Spring Web Flow, a flow is defined by three primary elements: states, transitions,and flow dat ...

  4. SPRING IN ACTION 第4版笔记-第八章Advanced Spring MVC-007-给flowl加权限控制&lt&semi;secured&gt&semi;

    States, transitions, and entire flows can be secured in Spring Web Flow by using the <secured> ...

  5. SPRING IN ACTION 第4版笔记-第八章Advanced Spring MVC-001- 配置SpringFlow&lpar;flow-executor、flow-registry、FlowHandlerMapping、FlowHandlerAdapter&rpar;

    一. 1.Wiring a flow executor <flow:flow-executor id="flowExecutor" /> Although the fl ...

  6. SPRING IN ACTION 第4版笔记-第八章Advanced Spring MVC-006-Pizza例子的支付流程

    一. 1. 2.payment-flow.xml <?xml version="1.0" encoding="UTF-8"?> <flow x ...

  7. SPRING IN ACTION 第4版笔记-第十一章Persisting data with object-relational mapping-006Spring-Data的运行规则&lpar;&commat;EnableJpaRepositories、&lt&semi;jpa&colon;repositories&gt&semi;&rpar;

    一.JpaRepository 1.要使Spring自动生成实现类的步骤 (1)配置文件xml <?xml version="1.0" encoding="UTF- ...

  8. 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 ...

  9. 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 ...

随机推荐

  1. redhat samba匿名登录服务器搭建

    smb服务器只需要yum install samba 安装起,并修改配置文件就可以匿名使用了.   smb配置文件,这里允许匿名登录.红色部分代表我共享出来文件夹参数code [root@localh ...

  2. Python Charts库的使用

    博客园格式不太好看,可以去本人CSDN博客 http://blog.csdn.net/ashic/article/details/52598664 http://nbviewer.jupyter.or ...

  3. 初学JDBC,防SQL注入简单示例

    在JDBC简单封装的基础上实现 public class UserDao{ public static void testGetUser(String userName) throws Excepti ...

  4. MVC开发过程中的疑难杂症

    MVC使用客户端验证 <script src="@Url.Content("~/Scripts/jquery-1.5.1.min.js")" type=& ...

  5. NOIP 2015 神奇的幻方

    模拟,注意为偶数的情况 #include<cstdio> #include<cstring> #include<cstdlib> #include<iostr ...

  6. Discuz&excl;NT中集成Memcached分布式缓存

    大约在两年前我写过一篇关于Discuz!NT缓存架构的文章,在那篇文章的结尾介绍了在IIS中如果开启多个应用程序池会造成多个缓存实例之间数据同步的问题.虽然给出了一个解决方案,但无形中却把压力转移到了 ...

  7. 常用的模式、JSON与DTO

    表现层的设计(一)——常用的模式.JSON与DTO 上几篇博文介绍了 业务逻辑层和数据访问层,我认为写博文的作用主要是向业界的读者交流一种思想,点到为止,至于学习架构设计,通过几篇博文是讲不清楚的,还 ...

  8. Java基础知识拾遗&lpar;一&rpar;

    Java Threads 1. 创建线程的三种方法? 继承Thread类: 实现Runnable接口: 使用Executor框架创建一个线程池. 每个线程都有优先级(Thread.MAX_PRIORI ...

  9. 8&period;23&period;4 IO-输入输出16个流

    字节流: FileInputStream FileInputStream fIn = new FileInputStream("1.avi");   FileOutputStrea ...

  10. PHP常见错误汇总

    日常开发和调试的时候,经常会遇到一些错误,光怪陆离的不知所以,所以,特此将错误汇总一下,借鉴!!! 1. 原因分析:  一般可能是该文件出现了问题,检查一下代码和格式,是否出现开始的地方出现了空格,或 ...