国产探花免费观看_亚洲丰满少妇自慰呻吟_97日韩有码在线_资源在线日韩欧美_一区二区精品毛片,辰东完美世界有声小说,欢乐颂第一季,yy玄幻小说排行榜完本

首頁 > 學院 > 開發設計 > 正文

SpringWebFlow(一)

2019-11-14 15:27:12
字體:
來源:轉載
供稿:網友

摘自http://hengstart.VEvb.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>


發表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發表
主站蜘蛛池模板: 肥乡县| 东山县| 喀喇| 斗六市| 龙口市| 白水县| 浦江县| 垫江县| 修文县| 濮阳县| 九龙坡区| 越西县| 通许县| 卢龙县| 永善县| 健康| 富川| 平罗县| 江华| 廉江市| 德阳市| 中牟县| 桂阳县| 辽中县| 永登县| 澳门| 金华市| 多伦县| 揭阳市| 安图县| 吉隆县| 石河子市| 长海县| 来宾市| 马龙县| 长乐市| 墨竹工卡县| 靖宇县| 渝北区| 赤水市| 太白县|