使用 WebFlowEditor 开发SWF应用 转自:http://www.nirvanastudio.org/nicholas/SWFEditor.htm 如果你还不了解Spring Web Flow,请参考Spring Web Flow这篇文章。 如果你已经开始对Spring Web Flow感兴趣了,那么我们开始着手了解如何独自开发SWF应用了。 首先,一个好的开发环境能够节省很多时间,这里我介绍一下如何使用Eclipse + WebFlowEditor开发SWF应用。 安装:- 下载Eclipse,我用的是3.1 M6版本。
- 下载Spring Framework和Spring Web Flow
- 安装plug-in,首先要装一个Spring IDE,之后要装Eclipse GEF,最后装Spring WebFlowEditor。
安装插件可以通过Help->Software Updates->Find and Install->Search for new festures to install->New Remote Site的办法,添加插件下载页的方式直接通过eclipse下载安装。 Spring IDE: http://springide.org/updatesite/ WebFlowEditor: http://springide.org/updatesite_dev GET: 通过默认的Eclipse.org update site安装,或者直接从eclipse网站下载安装 配置:- 新建一个Java Project,在Package Explorer选中项目点右键选择Add Spring Project Nature
- 我认为是很重要的一点,很多朋友都很疑惑Spring IDE在哪里,其实默认情况下这个View并没有显示出来,我们在Window->Show View->Other里面添加它到开发界面上。其实Spring IDE和Spring WebFlow的最大特点也就是能够以图形的方式直观的给人一个大体的映像,这样一来就能很好的看清Beans之间的联系。
- 在Spring Beans和Spring WebFlow里面添加配置信息,主要就是设定applicationContext.xml和xxxFlow.xml(Web Flow 定义),一切配置好后,就可以Show Graph和Show WebFlow Editor的方式显示出图形界面。有图形界面做起来就方便多啦:-)

图1 - Spring IDE 视图 第一个应用:这个例子来源于Spring Web Flow发行包内的例子 - fileupload,这是一个很简单的例子,流程也很简单。它采用了Spring MVC,最后我尝试着将它转换成Struts MVC。 在WEB-INF下的upload-flow.xml如下: <?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE webflow PUBLIC "-//SPRING//DTD WEBFLOW//EN"
"http://www.springframework.org/dtd/spring-webflow.dtd">
<webflow id="upload" start-state="selectFile.view">
<view-state id="selectFile.view" view="selectFile.view">
<transition on="submit" to="bindAndValidate"/>
</view-state>
<action-state id="bindAndValidate">
<action bean="upload.process"/>
<transition on="success" to="confirmation.view"/>
<transition on="error" to="selectFile.view"/>
</action-state>
<view-state id="confirmation.view" view="confirmation.view">
<transition on="back" to="selectFile.view"/>
</view-state>
</webflow>
通过Spring Web Flow Editor生成的流程图如下:
图2- fileupload 流程 在这个应用里,所有的view都放在了WEB-INF/jsp里面,每个标单里面必须有这样一个隐藏域: <INPUT type="hidden" name="_flowExecutionId" value="<%=request.getAttribute("flowExecutionId") %>">
用于SWF判断流程执行位置。 SelectFile.view ==> WEB-INF/jsp/selectFile.view.jsp,在这个View里面还有一个隐藏域: <INPUT type="hidden" name="_eventId" value="submit">
这个用于表示事件ID,就是transition的on属性,这样标示就能让spring知道执行哪个transitioin了。 与Struts集成:Spring提供的例子是与Spring MVC集成的,我尝试将它换成了Struts。 1、在struts-config.xml里面加入Spring Plugin,并且定义SWF入口: <?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE struts-config PUBLIC
"-//Apache Software Foundation//DTD Struts Configuration 1.2//EN"
"http://jakarta.apache.org/struts/dtds/struts-config_1_2.dtd">
<struts-config>
<form-beans>
<form-bean name="actionForm" type="org.springframework.web.struts.BindingActionForm"/>
</form-beans>
<global-forwards>
<forward name="confirmation.view
|