尊敬的 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 团队