星空网 > 软件开发 > Java

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的设置都是用Spring WebFlow的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标签,表示多个出口。 
一个完整的<flow                 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的<flow                 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>




原标题:Spring WebFlow(一)

关键词:Spring

*特别声明:以上内容来自于网络收集,著作权属原作者所有,如有侵权,请联系我们: admin#shaoqun.com (#换成@)。

国内手机怎么上twitter:https://www.kjdsnews.com/a/562703.html
他阶梯式拉长品牌增涨曲线,成为东南亚时尚行业Top品牌!:https://www.kjdsnews.com/a/563702.html
技术赋能制胜品牌出海,店匠SHOPLAZZA 助力开启跨境新时代:https://www.kjdsnews.com/a/563703.html
大卖单次融资过亿美金!谁是8月“跨境吸金王”?:https://www.kjdsnews.com/a/564702.html
梦碎亚马逊?中国卖家市场份额下降:https://www.kjdsnews.com/a/564703.html
数百个店铺被封,这个大卖又被深交所盯上了:https://www.kjdsnews.com/a/564704.html
如何从抖音上多挣钱?记住这12个字 :https://www.kjdsnews.com/a/1836445.html
连麦专家:2024年到底如何做小红书? :https://www.kjdsnews.com/a/1836446.html
相关文章
我的浏览记录
最新相关资讯
海外公司注册 | 跨境电商服务平台 | 深圳旅行社 | 东南亚物流