<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans" 
 xmlns:context="http://www.springframework.org/schema/context" 
 xmlns:p="http://www.springframework.org/schema/p" 
 xmlns:mvc="http://www.springframework.org/schema/mvc" 
 xmlns:tx="http://www.springframework.org/schema/tx"
 xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" 
 xsi:schemaLocation="http://www.springframework.org/schema/beans 
      http://www.springframework.org/schema/beans/spring-beans-3.0.xsd 
      http://www.springframework.org/schema/context 
      http://www.springframework.org/schema/context/spring-context.xsd 
      http://www.springframework.org/schema/tx
      http://www.springframework.org/schema/tx/spring-tx-2.5.xsd
      http://www.springframework.org/schema/mvc 
      http://www.springframework.org/schema/mvc/spring-mvc-3.0.xsd">

<bean id="viewResolver" class="org.springframework.web.servlet.view.InternalResourceViewResolver">
        <property name="prefix" value="/"/>
        <property name="suffix" value=".jsp"/>
      </bean>
      <bean class="org.springframework.web.servlet.handler.BeanNameUrlHandlerMapping"/>
      <bean class="org.springframework.web.servlet.handler.SimpleUrlHandlerMapping">  
            <property name="mappings">  
                <props>  
                    <prop key="/index">index1</prop>  
                    <prop key="/shopping">flowController</prop>
                </props>  
            </property>  
        </bean>  
      <bean id="index1" class="org.springframework.web.servlet.mvc.ParameterizableViewController" >
         <property name="viewName" value="index"></property>
       </bean>
      
       <bean id="flowController" class="org.springframework.webflow.mvc.servlet.FlowController">
        <property name="flowExecutor" ref="flowExecutor" />
      </bean>
              <!--FlowController可以理解为时flow的入口,也就是spring mvc与spring web flow的结合点,将请求交给词控制器处理就表示进入到flow中去,具体进入到哪一个flow就是靠flowExecutor来判断,判断的方式是根据请求的URL,那么在本例中将会进入到id为shopping的flow-->

</beans>

<?xml version="1.0" encoding="UTF-8"?>
<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-2.5.xsd 
    http://www.springframework.org/schema/webflow-config 
    http://www.springframework.org/schema/webflow-config/spring-webflow-config-2.0.xsd">
    <webflow:flow-executor id="flowExecutor" flow-registry="flowRegistry" />
    <!-- 所有 flow的定义文件它的位置在这里进行配置, flow-builder-services 用于配置 flow 的特性 -->
    <webflow:flow-registry id="flowRegistry" flow-builder-services="flowBuilderServices">
        <webflow:flow-location path="/WEB-INF/flows/shopping.xml" id="shopping" />
        <webflow:flow-location path="/WEB-INF/flows/addToCart.xml" id="addToCart" />
    </webflow:flow-registry>
    <!--Web Flow 中的视图通过 MVC 框架的视图技术来呈现 -->
    <webflow:flow-builder-services id="flowBuilderServices" view-factory-creator="mvcViewFactoryCreator" />
    <!-- 指明 MVC 框架的 view resolver ,用于通过 view 名查找资源 -->
    <bean id="mvcViewFactoryCreator" class="org.springframework.webflow.mvc.builder.MvcViewFactoryCreator">
        <property name="viewResolvers" ref="viewResolver" />
    </bean>
</beans>

<?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">
 <!-- view-state中的view对应jsp文件夹中的jsp页面,on是触发事件,to对应state id -->
<!--      <var name="mycart" class="bean.Cart"/>  表示定义一个名为mycart的变量,其值为bean.Cart类对象
             这种方式可以使用spring注解代替:@Component("mycart")
-->
   <on-start> <!-- 表示在进入此flow之前执行 -->
      <set name="conversationScope.cart" value="mycart"></set> <!-- 表示将mycart放入到conversation范围内的cart中 -->
   </on-start> 
     <view-state id="viewCart" view="/jsp/viewCart" > <!-- 我们可以看到这是此flow的第一个state,那么当进入到这个flow时 -->
       <on-render>  <!--在这个视图渲染之前,执行里面的业务逻辑-->          <!--首先执行这个state,即进入到viewCart页面 -->
         <evaluate expression="productService.getProducts()" result="viewScope.products"/> 
           <!-- expression表达式表示业务逻辑,将该方法的返回值放入到view范围内的products中 -->
      </on-render> 
       <transition on="submit" to="viewOrder"><!--当在此状态下,如果触发submit,则会转向viewOrder状态 -->
       </transition> 
      <transition on="addToCart" to="addProductToCart"/>
   </view-state> 
    <view-state id="viewOrder" view="/jsp/viewOrder">
        <transition on="confirm" to="orderConfirmed">
        </transition>
    </view-state>
    <view-state id="orderConfirmed" view="/jsp/viewConfirmed">
        <transition on="returnToIndex" to="returnToIndex">
        </transition>
    </view-state>
    <end-state id="returnToIndex" view="index">
    </end-state><!-- 次flow的结束状态 ,不能再转向其他状态-->
    
    <subflow-state id="addProductToCart" subflow="addToCart"> <!-- 子流,subflow表示子flow的id -->
         <transition on="productAdded" to="viewCart" /> 
   </subflow-state>

</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"> 
   <on-start>  
  <set name="requestScope.productId" value="requestParameters.productId"/>   
  </on-start> 
 <action-state id="addToCart"> 
   <evaluate expression="cart.addItem(productService.getProduct(productId))"/> 
   <transition to="productAdded"/> 
 </action-state> <!-- 此state就是用来处理业务逻辑的 -->
 <end-state id="productAdded"/> 
</flow>

Spring web flow 配置文件相关推荐

  1. 笔记41 Spring Web Flow——Demo

    订购披萨的应用整体比较比较复杂,现拿出其中一个简化版的流程:即用户访问首页,然后输入电话号(假定未注册)后跳转到注册页面,注册完成后跳转到配送区域检查页面,最后再跳转回首页.通过这个简单的Demo用来 ...

  2. Spring Web Flow 简单实现-自定义配置文件位置

    前言 在文章 Spring Web Flow 简单实现 中,我们把Web Flow 的的配置文件和 jsp 页面文件统一放置在了 WEB-INF 目录下,事实上,那种情况下我们不得不这样做. 这片文章 ...

  3. 用Spring Web Flow和Terracotta搭建Web应用

    什么是Spring Web Flow? Spring Web Flow是Spring Framework中的web应用组件,它提供了一种编写有状态和基于会话的web应用的简便手段.Spring Web ...

  4. Spring Web Flow实例教程

    目录: 参考文献 购物车用例 什么情况下可以使用 Spring Web Flow? 配置 Spring Web MVC 配置 Spring Web Flow 2.0 的基础 在购物车示例应用中配置 S ...

  5. Spring Web Flow 2.0 入门详解

    目录: 参考文献 购物车用例 什么情况下可以使用 Spring Web Flow? 配置 Spring Web MVC 配置 Spring Web Flow 2.0 的基础 在购物车示例应用中配置 S ...

  6. Spring Web Flow 入门demo(三)嵌套流程与业务结合 附源码

    转载地址 ; http://blog.csdn.net/hejingyuan6/article/details/46723021 上篇博客我们说spring web Flow与业务结合的方式主要有三种 ...

  7. Spring Web Flow 入门demo(一)简单页面跳转 附源码

    转载地址 http://blog.csdn.net/hejingyuan6/article/details/46508821 spring Web Flow (SWF)是Spring Framewor ...

  8. 笔记36 Spring Web Flow——配置

    Spring Web Flow是一个Web框架,它适用于元素按规定流程运行的程序.Spring Web Flow是Spring MVC的扩展,它支持开发基于流程的应用程 序.它将流程的定义与实现流程行 ...

  9. 《Spring Web Flow 实践》

    <Spring Web Flow 实践> 在<Spring In Action>这本书上的第八章介绍了Spring Web Flow的相关知识. 在<Spring In ...

最新文章

  1. python标准库学习4
  2. viewpager默认界面_使用默认方法的界面演变–第一部分:方法
  3. 无中生有!没有视觉信号的视觉语音增强
  4. Excel文档VBA代码自动删除
  5. Lync2010标准版部署
  6. 利用Linq对集合元素合并、去重复处理
  7. hdu1023-----卡特兰数
  8. pycharm汉化(搜索不到插件的参考第二中方法)
  9. 戴尔服务器r720u盘装系统,DELL R720服务器U盘安装操作系统指南
  10. 网络工程师HCNA认证学习笔记Day1
  11. vs2017 安装MFC
  12. 四种隔离级别及应用场景
  13. Unity 引擎 Managed Stripping Level 遇到的坑
  14. 【ggplot】复杂柱状图:自定义颜色、标签、位置、坐标轴和主题
  15. 游戏开发主要学哪些课程?
  16. 使用app inventor快速开发安卓app(第二课,音乐播放器)
  17. 蚂蚁花呗账单分期和交易分期的费用如何计算?
  18. Day17:web前端开发面试题
  19. MVVM理解 ——(2)数据劫持
  20. java打包把依赖也打进去_maven打包时把依赖的jar包打进去

热门文章

  1. 内存问题检查利器——Purify
  2. 听音乐看节目是计算机的什么,2014家用电脑既能听音乐又能看影视节目 .doc
  3. 实用版ChatBing论文阅读助手教程+新测评
  4. 二叉搜索树(BST)分析及实现
  5. Linux命令之ulimit命令
  6. 三层交换机与路由互联配置(华为设备)
  7. 043:cesium加载Bing地图(多种形式)
  8. stn专线和otn有什么区别_中国电信开辟政企OTN专网新业务市场
  9. IOS笔记UI--禁止scrollview上下拖动
  10. html5 冰块,酸甜冰块的做法