Spring WebFlow(一)

摘自http://hengstart.iteye.com/blog/819748

Spring WebFlow的关注点的层次比Sping MVC 或者是 Structs 更高。不只是关注于如何e构建Web界面,更加关注于流程,也就是Flow。

在Spring WebFlow里面,每个Flow都包括了几个步骤,称为‘State’。 每一个步骤里面都有一个View,View里面的事件处理由State来执行。这些事件会触发一些事务,这些事务会根据之前设置好的配置,跳转到其他的State上面去。

在Spring WebFlow中,flow的设置都是用XML文件来表示。
Spring WebFlow的XML定义:
Flow标签:<flow/>是根元素,所有的定义从这个元素开始。
State标签:<view-state/>用来表示一个拥有View的State。在这个标签里面,指定了用于描述View的文件的位置。这个位置是约定俗成的,由设置的id来指定。比如<view-state id=”enterBookDetails”/>,那么这个State的View的描述文件为enterBookDetails.xhtml。如果这个Flow的定义文件存放在/WEB-INF/xxxx/booking/目录下面,那么这个View的定义文件就是/WEB-INF/xxxx/booking/enterBookDetails.xhtml。
transaction标签:<transaction/>是view-state的子标签,定义一个页面转向,比如<transaction on=”submit” to=”reviewBooking”/>,则是说明了当触发submit事件的时候,转到下面一个state,转向的state的id为reviewBooking。
end-state标签:<end-state/>这个表示flow的出口,如果某个transaction指向了一个end-state标签,表示这个flow已经结束。一个flow可以有多个end-state标签,表示多个出口。 
一个完整的XML文件例子:
<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 id="enterBookingDetails">
          <transition on="submit" to="reviewBooking" />
    </view-state>
    <view-state id="reviewBooking">
          <transition on="confirm" to="bookingConfirmed" />
          <transition on="revise" to="enterBookingDetails" />
          <transition on="cancel" to="bookingCancelled" />
    </view-state>
    <end-state id="bookingConfirmed" />
    <end-state id="bookingCancelled" />
</flow>

Actions:一个Spring WebFlow里面很重要的概念,从上面可以看出,view-state、transaction、end-state标签只是表示Flow的流程,页面跳转,里面没有说明业务逻辑的操作。Action就是用来调用这些业务逻辑操作的。
在下面几个点中,我们可以调用Action:
1.Flow开始的时候
2.进入State的时候
3.View进行渲染的时候
4.transaction执行的时候
5.state退出的时候
6.Flow结束的时候

evaluate:这个标签可能是Action里面最常使用的标签,用Spring定义的表达式来确定一个Action去调用哪个Spring Bean的方法,然后返回值、返回类型是什么。
例如:<evaluate expression="bookingService.findHotels(searchCriteria)" result="flowScope.hotels" result-type="dataModel"/>,这里面就说明了这个action需要调用bookingService这个bean的findHotels这个方法,传入的参数是searchCriteria这个bean,返回的结果是flowScope(这个是所属的Flow的数据模型)里面的hotels这个数据模型(这个后面会提到)。

一个完整的包含Action的xml文件例子
<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="hotelId" />
        <on-start>
            <evaluate expression="bookingService.createBooking(hotelId,currentUser.name)" result="flowScope.booking" />
        </on-start>
        <view-state id="enterBookingDetails">
            <transition on="submit" to="reviewBooking" />
        </view-state>
        <view-state id="reviewBooking">
            <transition on="confirm" to="bookingConfirmed" />
            <transition on="revise" to="enterBookingDetails" />
            <transition on="cancel" to="bookingCancelled" />
        </view-state>
        <end-state id="bookingConfirmed" />
        <end-state id="bookingCancelled" />
</flow>

时间: 2024-08-02 12:14:51

Spring WebFlow(一)的相关文章

使用spring webflow,在前台页面中如何显示后端返回的错误信息

刚刚接触spring webflow,相关的资料并不是很多,并且大都是那种入门的 .xml文件的配置. 用到的CAS 最新的4.0版本用的就是web-flow流,前台页面使用的是表单提交.于是我就碰到了一个问题,问题描述如下: 第一次输入错误的用户名密码提示用户名密码错误,第二次输入了正确的用户名和密码仍然报错,校验不通过. 在使用cas之前的登录页面如果输入用户名和密码错误的话,会弹出alert提示框,这个是使用ajax请求实现的.而ajax请求的一般都是那种spring mvc的contro

Spring webflow + Jpa + Hibernate运行时无响应问题处理

问题现象: 使用Spring webflow过程的页面需要从Mysql查询数据,在前台展现出来,在查询几次后页面就没有响应,服务器的日志最后一条就是Hibernate的SQL语句. 运行环境: JRE:1.8 Spring framework:4.3.8.RELEASE Spring webflow:2.4.5.RELEASE Spring data jpa:1.11.4.RELEASE Hibernate:5.2.5.Final MySql:5.7.14 Tomcat:8.0(使用tomcat

spring webflow

最近看了一段时间的spring-webflow,说一下自己的见解吧. 首先说一下关于spring-webflow的技术文档太少了,网上就只有一个入门篇,讲的比较笼统,但还是推荐一下, Spring Web Flow 2.0 入门,又看了下英文文档,先说下心得 1.<view-state id="viewCart" view="viewCart"> <on-render> <evaluate expression="produc

草草弄完SPRING WEB-FLOW

明天白天再慢慢看原理吧. 今天先把代码实习一次. 作作截图存照.

Spring 教程(一)

一.Spring是什么 通常说的Spring其实指的是Spring Framework,它是Spring下的一个子项目,Spring围绕Spring Framework这个核心项目开发了大量其他项目,比如Spring Security,Spring Data,Spring WebFlow等等. Spring是为简化Java EE开发而生,而在Java EE中使用最多的就是Spring Framework,接下来我们主要就是学习Spring Framework. Spring Framework包

Thymeleaf模板引擎+Spring整合使用方式的介绍

尊重原创,原文地址为:https://www.cnblogs.com/jiangchao226/p/5937458.html 前言 这个教程介绍了Thymeleaf与Spring框架的集成,特别是SpringMvc框架. 注意Thymeleaf支持同Spring框架的3.和4.版本的集成,但是这两个版本的支持是封装在thymeleaf-spring3和thymeleaf-spring4这两个独立的库中,项目中需要根据实际情况分别引用. 样例代码针对的是spring4.,但一般情况下,spring

eclipse 常用插件

转自:http://blog.csdn.net/fmynjy/article/details/51500989 开发过程中的常用Eclipse插件,按字母排序: (1)    AmaterasUML        介绍:Eclipse的UML插件,支持UML活动图,class图,sequence图,usecase图等:支持与Javaclass/interface之间的相互导入导出.        官方网站:http://amateras.sourceforge.jp/cgi-bin/fswiki

springMVC基础篇

 对于一个不懂技术的人来说springMVC是什么呢?有人会说:"春天里的MVC"这也许就是春天里的几个字母,不错在我没有接触java框架的时候留给我的记忆就是这样的.那么现在接触到了就让我们来好好讨论一下springMVC到底是什么吧? 一.是什么? 百度百科上这样解释:Spring MVC属于SpringFrameWork的后续产品,已经融合在Spring WebFlow里面.Spring 框架提供了构建 Web 应用程序的全功能 MVC 模块.使用 Spring 可插入的 M

单点登录系统(SSO)之CAS(中央认证服务)

SSO(Single Sign On)单点登录系统,是在多个系统中值要求只要登录一次,就可以用已登录的身份访问多个系统,去掉了每次访问不同的系统都要重新登录的弊端. CAS(中央/集中认证服务):The Central Authentication Service project, more commonly referred to as CAS is an authentication system originally created by Yale University to provid