尊敬的 Spring 社群:,
Spring Web Flow 是 Spring 社群的產品,專注於 Web 應用中使用者介面流程的編排。
此版本包含許多改進和幾個令人興奮的新功能。 我們認為這是迄今為止最穩定的版本,也是最終使 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 配置 Schema (7)。
- (1) Render actions 在響應渲染之前執行應用行為。 當檢視狀態被要求進行可渲染檢視選擇時,或者在由重定向或瀏覽器重新整理按鈕觸發的重新整理時,將呼叫渲染動作。 下面的示例展示了一個在渲染結果檢視之前執行電話簿搜尋的渲染動作。
<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-based)可以針對流程執行根 RequestContext 可訪問的任何物件,包括任何作用域(例如流作用域)中的物件。 下面的示例展示了一個 evaluate-action,它在 "game" 流作用域 bean 上呼叫 "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 在流程作用域等作用域型別中設定屬性值。 屬性可以是頂層屬性或巢狀屬性路徑上的屬性。 下面的示例展示了一個 set-action,它在 flash scope 中將 "fileUploaded" 屬性設定為 "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 是一種新的作用域型別,用於在重定向和檢視的任何重新整理期間保留屬性。 當觸發事件以從檢視轉換出去時,flash scope 會被清除。 下面的完整流程定義示例展示了使用 flash scope 將 "fileUploaded" 屬性暴露給 selectFile 檢視狀態,以便在成功上傳後顯示成功訊息。
<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) “始終在暫停時重定向”無需特殊編碼即可為您提供預設的 POST+REDIRECT+GET 行為。 現在,預設情況下,當進入檢視狀態時,會自動發出重定向。 這會觸發重新整理到流程執行 URL,該 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">
<!-- Launches new flow executions and resumes existing executions. -->
<flow:executor id="flowExecutor" registry-ref="flowRegistry"/>
<!-- Creates the registry of flow definitions for this application -->
<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、evaluate actions 和“單鍵”流程執行重定向。
- Birthdate - 展示 Struts 整合
- Fileupload - 展示多分部檔案上傳、set actions 和 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,以獲取有關釋出歸檔內容和示例的更多資訊。
所有示例專案都是可以直接匯入到 Eclipse 中的 Spring IDE 專案。
感謝所有支援此版本的使用者。 Spring Web Flow 1.0 現在... 終於... 就在眼前了。
盡情使用!
Spring Web Flow 團隊