亲爱的 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 团队