我们已经知道如何从页面上触发动作来激活flow的transition,我们现在思考问题,如果这个动作需要用到flowScope上的数据,那么我们如何用程序来和flowScope交互呢?
方法很简单,我们在业务方法中加一个参数,参数类型为RequestContext,用这个类就可以和flowScope进行交互了:
- /**
- * remove the AppInfo from flow scope
- */
- public void removeAppInfo(RequestContext context) {
- // clear all the information which has been stored in this object
- context.getFlowScope().remove("appInfo");
- //context.getFlowScope().remove("appInfoJSONData");
- context.getFlowScope().put("appInfoJSONData", new JSONObject().toString());
- context.getFlowScope().put("hasAppInfoData",false);
- }
比如,这里我们定义了一个业务方法叫removeAppInfo,我们让它的逻辑为从flowScope上删除appInfo的数据,然后把appInfoJSONData清零,最后吧hasAppInfoData设为false .
这个方法的调用,我们还是通过绑定页面上的某个事件来触发调用,和上一篇文章一样,所以我这里就略去了。假设是在defineApp.jsp页面上,并且_eventId为cancel时候触发调用:
- <portlet:actionURL var="cancel">
- <portlet:param name="execution" value="${flowExecutionKey}" />
- <portlet:param name="_eventId" value="cancel" />
- </portlet:actionURL>
那么在flowScope上,为了绑定这段java业务逻辑代码,我们就在flow定义文件中view-state为defineApp的代码配置如下:
- <view-state id="defineApp" >
- ...
- <transition on="cancel" to="aerEnvList" >
- <evaluate expression="defineAppService.removeAppInfo(flowRequestContext)" />
- <evaluate expression="defineProjectService.removeProjectInfo(flowRequestContext)" />
- <evaluate expression="defineHostVipService.removeHostVipInfo(flowRequestContext)" />
- <evaluate expression="defineDBSrvService.removeDBServiceInfo(flowRequestContext)"/>
- </transition>
- </view-state>
这里可以看出来,在04行,只要传一个内置变量名为flowRequestContext,就可以轻松的调用对应业务方法了,而这个flowRequestContext中的内容,就对应了我们java类org.springframeowork.webflow.execution.RequestContext
转载于:https://blog.51cto.com/supercharles888/1138934