親愛的 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 引入了強大的新功能,例如渲染動作 (1)、評估動作 (2)、設定動作 (3)、快閃記憶體範圍 (4)、流程執行屬性 (5) 和暫停時總是重定向 (6)。它提供了增強的文件、更好的流程定義驗證、智慧預設值以及一個完整的自定義 Spring 2.0 配置 Schema (7) 用於配置流程執行引擎。
- (1) 渲染動作在響應渲染之前執行應用程式行為。當檢視狀態被要求進行可渲染檢視選擇時,在進入或由重定向或瀏覽器重新整理按鈕觸發重新整理時,都會呼叫渲染動作。以下示例顯示了一個渲染動作,它在渲染結果檢視之前執行電話簿搜尋。
<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) 評估動作根據流程執行狀態評估表示式。預設情況下,表示式(基於 OGNL)可以針對流程執行的根 RequestContext 可訪問的任何物件,包括任何範圍(例如流程範圍)中的物件。以下示例顯示了一個評估動作,它呼叫“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) 設定動作設定範圍型別中的屬性值,例如流程範圍。該屬性可以是頂級屬性,也可以是巢狀屬性路徑上的屬性。以下示例顯示了一個設定動作,它在快閃記憶體範圍中將“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) 快閃記憶體範圍是一種新的範圍型別,用於跨重定向和檢視的任何重新整理持久化屬性。當訊號觸發離開檢視的事件時,快閃記憶體範圍將被清除。以下完整的流程定義示例展示瞭如何使用快閃記憶體範圍將“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 配置方言極大地簡化了系統配置,並提供了強大的驗證和工具支援。現在,配置 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 的最佳方法之一是檢視和逐步學習示例應用程式。我們建議檢視所有示例,並根據需要從一開始就補充參考手冊中的材料。此版本附帶了十個示例應用程式,每個應用程式都演示了一組獨特的產品功能。這些示例包括:
- 電話簿 - 演示大多數功能(包括子流)的原始示例
- 銷售項 - 演示帶有條件轉換、流程執行重定向、自定義文字欄位格式和續接的嚮導
- 流程啟動器 - 演示啟動和恢復流程的所有可能方式
- 專案列表 - 演示 REST 風格的 URL 和內聯流程
- 運費計算 - 演示 Spring Web Flow 與 Ajax 技術結合使用
- 猜數字 - 演示有狀態 Bean、評估操作和“單鍵”流程執行重定向。
- 出生日期 - 演示 Struts 整合
- 檔案上傳 - 演示多部分檔案上傳、設定操作和快閃記憶體範圍
- 電話簿-Portlet - Portlet 環境中的電話簿示例(注意流程定義沒有變化)
- 銷售項-JSF - JSF 環境中的銷售項示例
要快速評估示例應用程式,只需
- 解壓縮 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 團隊