使用Spring Web Flow,使用springwebflow

來源:互聯網
上載者:User

使用Spring Web Flow,使用springwebflow

陳科肇-http://blog.csdn.net/u013474104/article/details/44541021

=========

1.簡介

a.Spring Web Flow是一個web架構,它適用於元素按規定流程啟動並執行程式,如和我們熟知的Sturts一樣,但Struts沒能將流程的定義與實現流程行為的類和視圖分離開來;

b.Spring Web Flow是Spring MVC的擴充,它支援開發基於流程的應用程式。它將流程的定義與實現流程行為的類和視圖分離開來;

c.Spring Web Flow是Spring架構的子項目,但不是Spring架構的一部分;

2.安裝Spring Web Flow

基於簡介c點的介紹,因此我們需要安裝Spring Web Flow。

在maven項目的pom.xml設定檔中添加jar包依賴,如下:

<dependency><groupId>org.springframework.webflow</groupId><artifactId>spring-webflow</artifactId><version>2.2.1.RELEASE</version></dependency>
關聯下載下來有好多jar檔案,但我們只需要binding和webflow這兩個jar檔案,其它的是Spring Web Flow與JSF和JavaScript相協作時所用到的。
3.在Spring中使用Web Flow

Spring Web Flow是構建於Spring MVC基礎之上的,這就意味著所有的流程請求都要首先經過Spring MVC的DispatcherServlet。因此我們要在Spring應用上下文中配置一些Bean來處理流程請求並執行流程。

配置Spring Web Flow:

步驟:a.執行器,b.註冊表,c.處理請求(請求和響應)

<beans xmlns="http://www.springframework.org/schema/beans"xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"xmlns:mvc="http://www.springframework.org/schema/mvc"xmlns:context="http://www.springframework.org/schema/context"xmlns:flow="http://www.springframework.org/schema/webflow-config"xsi:schemaLocation="http://www.springframework.org/schema/mvc http://www.springframework.org/schema/mvc/spring-mvc.xsdhttp://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-3.0.xsd        http://www.springframework.org/schema/webflow-config        http://www.springframework.org/schema/webflow-config/spring-webflow-config-2.0.xsd"><!-- Spring Web Flow +++++++++++++++++++++++++++begin --> <!--  1. 織入流程執行器:流程執行器驅動流程的執行(當使用者進入一個流程時,流程執行器會為使用者建立並啟動一個流程執行執行個體。當流程暫停時候(如為使用者展示視圖時),流程執行器會在使用者執行操作後恢複流程)。 雖然流程執行器負責建立和執行流程,並不負責載入流程定義,這個責任落在了流程註冊表(flow registry)中  -->  <flow:flow-executor id="flowExecutor" flow-registry="flowRegistry"/>  <!--   2.  配置流程註冊表:載入定義的流程,讓執行器能夠使用它們  定義的流程:base-path+value=/WEB-INF/flows/*-flow.xml  流程的ID是如何計算的:/[WEB-INF/flows](流程註冊表基本路徑)/[wwo](流程ID)/[wwo-flow.xml](流程定義檔案)  顯示聲明流程定義檔案(ID、URL):<flow:flow-location id="login" path="/WEB-INF/flows/*-flow.xml"/>,去除<flow:flow-registry>的base-path屬性   -->   <flow:flow-registry id="flowRegistry" base-path="/WEB-INF/flows">   <flow:flow-location-pattern value="*-flow.xml"/>   </flow:flow-registry>   <!--    3.   處理流程請求(請求定向指定):使用Spring MVC處理時,我們是通常通過DispatcherServlet將請求分發給控制器。但對於   流程而言,我們需要FlowHandlerMapping來協助DispatcherServlet將流程請求發送給Spring Web Flow。    -->    <bean class="org.springframework.webflow.mvc.servlet.FlowHandlerMapping">    <property name="flowRegistry" ref="flowRegistry"/>    </bean>    <!--      4.               響應請求(相當於Spring MVC的控制器):     -->     <bean class="org.springframework.webflow.mvc.servlet.FlowHandlerAdapter">      <property name="flowExecutor" ref="flowExecutor"/>     </bean> <!-- Spring Web Flow +++++++++++++++++++++++++++end --></beans>
4.流程的組件

在Spring Web Flow中,流程主要由3個元素定義的:狀態、轉移和流程資料。

狀態:是商務邏輯執行、做出決策或將頁面展現給使用者;

轉移:從一個狀態轉移到另一個狀態;

流程資料:在流程處理中,收集的一些資料(流程的當前狀況)。

a.狀態


b.轉移


c.流程資料


5.開始定義流程


暫時用不上,先不寫了!

待續....

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.