親愛的 Spring 社群:
Spring Web Flow 是 Spring 社群的一個產品,專注於網頁應用程式中使用者介面流程的協調。
此版本包含許多改進和幾個令人興奮的新功能。我們認為它是迄今為止最穩定的版本,並且最終成為使 Spring Web Flow 1.0 最終路線圖功能完整的版本。Spring Web Flow 1.0 最終版本將於下週發佈,只有極少的變更。從現在到那時,我們鼓勵您測試 1.0 RC4,以幫助在 1.0 大發佈之前捕獲任何剩餘問題。
請注意,此版本中存在影響使用者的變更。1.0 RC3 或更早版本的使用者應查看升級指南,其中詳細概述了這些變更。
1.0 RC4 中的新增功能和值得注意的功能是一個令人興奮的列表,包括:
新增功能和值得注意的功能
作為 Spring Web Flow 1.0 最終版本之前的最終候選版本,Spring Web Flow 1.0 RC4 引入了強大的新功能,例如 render actions (1)、evaluate actions (2)、set actions (3)、flash scope (4)、flow execution attributes (5) 和 always redirect on pause (6)。它提供了增強的文件、更好的流程定義驗證、智慧預設值和完整的自訂 Spring 2.0 配置架構 (7),用於配置流程執行引擎。
- (1) Render actions 在呈現回應之前執行應用程式行為。當要求 view-state 選擇可呈現的視圖時,或者在由重新導向或瀏覽器重新整理按鈕觸發的重新整理時,將調用 render action。以下範例顯示了一個 render-action,它在呈現結果視圖之前執行電話簿的搜尋。
<view-state id="displayResults" view="searchResults">
<render-actions>
<bean-action bean="phonebook" method="search">
<method-arguments>
<argument expression="flowScope.searchCriteria"/>
</method-arguments>
<method-result name="results"/>
</bean-action>
</render-actions>
<transition on="newSearch" to="enterCriteria"/>
<transition on="select" to="browseDetails"/>
</view-state>
- (2) 評估動作 (Evaluate actions) 針對流程執行狀態評估表達式。表達式(預設基於 OGNL)可以針對從流程執行的根 RequestContext 可訪問的任何物件,包括任何 scope(例如 flow scope)中的物件。以下範例展示了一個 evaluate-action,它調用 flow scope bean "game" 上的 "makeGuess" 方法
<action-state id="makeGuess">
<evaluate-action expression="flowScope.game.makeGuess(requestParameters.guess)">
<evaluation-result name="guessResult"/>
</evaluate-action>
<transition on="CORRECT" to="showAnswer"/>
<transition on="*" to="enterGuess"/>
<transition on-exception="java.lang.NumberFormatException" to="enterGuess"/>
</action-state>
- (3) 設定動作 (Set actions) 在 scope 類型(例如 flow scope)中設定屬性值。該屬性可以是頂層屬性,也可以是巢狀屬性路徑中的屬性。以下範例展示了一個 set-action,它將 "fileUploaded" 屬性設定為 flash scope 中的 "true"。
<action-state id="uploadFile">
<action bean="uploadAction" method="uploadFile"/>
<transition on="success" to="selectFile">
<set attribute="fileUploaded" scope="flash" value="true"/>
</transition>
</action-state>
- (4) Flash scope 是一種新的 scope 類型,用於在重新導向和任何視圖的重新整理之間持續保存屬性。當發出事件以轉換出視圖時,flash scope 會被清除。以下完整的流程定義範例展示了如何使用 flash scope 來將 "fileUploaded" 屬性公開給 selectFile view-state,以便在成功上傳後顯示成功訊息。
<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-1.0.xsd">
<start-state idref="selectFile"/>
<view-state id="selectFile" view="fileForm">
<transition on="submit" to="uploadFile"/>
</view-state>
<action-state id="uploadFile">
<action bean="uploadAction" method="uploadFile"/>
<transition on="success" to="selectFile">
<set attribute="fileUploaded" scope="flash" value="true"/>
</transition>
</action-state>
</flow>
- (5) 流程執行屬性允許您設定自訂屬性,這些屬性可以影響流程執行行為。以下範例展示了在 Portlet 環境中(重定向通常不適用)將 "alwaysRedirectOnPause" 屬性設定為 false 的指示。
<flow:executor id="flowExecutor" registry-ref="flowRegistry">
<flow:execution-attributes>
<flow:alwaysRedirectOnPause value="false"/>
</flow:execution-attributes>
</flow:executor>
- (6) "暫停時始終重新導向 (Always redirect on pauses)" 為您提供預設的 POST+REDIRECT+GET 行為,而無需特殊編碼。現在,預設情況下,當進入 view state 時,會自動發出重新導向。這會觸發重新整理到在對話處於活動狀態時保持穩定的流程執行 URL。
- (7) 新的 Spring 2.0 Configuration Dialect 極大地簡化了系統配置,並提供了強大的驗證和工具支援。配置 webflow 的基礎架構現在就像定義兩個元素一樣簡單,如下所示:
<?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:flow="http://www.springframework.org/schema/webflow-config"
xsi:schemaLocation="
http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans-2.0.xsd
http://www.springframework.org/schema/webflow-config
http://www.springframework.org/schema/webflow-config/spring-webflow-config-1.0.xsd">
<!-- 啟動新的流程執行並恢復現有的執行。 -->
<flow:executor id="flowExecutor" registry-ref="flowRegistry"/>
<!-- 為此應用程式建立流程定義的 registry -->
<flow:registry id="flowRegistry">
<flow:location path="/WEB-INF/flows/**-flow.xml"/>
</flow:registry>
</beans>
有關這些功能的更多資訊,請參閱參考手冊。 Spring Web Flow 1.0 RC4 進一步完善了參考文檔,提供了 70 頁關於 SWF 使用的資訊。該手冊可以透過以下連結線上取得:HTML 和 PDF 格式。
開始使用
開始使用 Spring Web Flow 的最佳方法之一是查看並演練範例應用程式。我們建議您查看所有範例,並根據需要從一開始就補充參考手冊材料。該版本提供了十個範例應用程式,每個應用程式都演示了一組不同的產品功能。這些範例是:
- Phonebook - 原始範例,演示了大多數功能(包括子流程)
- Sellitem - 演示了一個具有條件轉換、流程執行重新導向、自訂文字欄位格式設定和延續的精靈
- Flowlauncher - 演示了啟動和恢復流程的所有可能方式
- Itemlist - 演示了 REST 風格的 URL 和內嵌流程
- Shippingrate - 演示了 Spring Web Flow 與 Ajax 技術的結合
- NumberGuess - 演示了有狀態 bean、評估動作和「單一金鑰」流程執行重新導向。
- Birthdate - 演示了 Struts 整合
- Fileupload - 演示了 multipart 檔案上傳、設定動作和 flash scope
- Phonebook-Portlet - Portlet 環境中的電話簿範例(請注意流程定義沒有更改)
- Sellitem-JSF - JSF 環境中的 sellitem 範例
要建構範例應用程式以進行快速評估,只需:
- 解壓縮 spring-webflow-1.0-rc4.zip 發佈封存檔
- 訪問 projects/spring-webflow/build-spring-webflow 目錄
- 執行 "ant dist" 目標。
- 請參閱 "target/artifacts" 目錄,其中包含每個範例的可部署 .war 檔案以及展開的 war 目錄。
有關發佈封存檔內容和範例的更多資訊,請分別參閱發佈 readme.txt 和 projects/spring-webflow/spring-webflow-samples/readme.txt。
所有範例專案都是 Spring IDE 專案,可以直接匯入到 Eclipse 中。
感謝所有支援此版本的人。 Spring Web Flow 1.0 現在... 終於... 即將推出。
祝您使用愉快!
Spring Web Flow 團隊