2015-05-13 210 views
1

我正在使用spring web流处理web应用程序。虽然我在flow.xml文件工作,我必须得决定状态就可以了这样的 -从flow.xml中打印日志

<decision-state id="checkPermissin">  
    <if test="requestParameters.canApprove" then="approve" else="warning" /> 
</decision-state> 

当一个请求到达flow.xml然后从它那里得到请求参数canApprove并测试它是否是真的还是假的。然后它进入approvewarning状态。

我的问题是 - 我可以从flow.xml文件记录/打印canApprove的状态吗?

回答

2

您可以在“决定状态”的末尾添加一个退出标记,并在类路径上调用任何服务方法,spring bean或静态方法。

试试这个(未经测试):

<decision-state id="checkPermissin">  
    <if test="requestParameters.canApprove" then="approve" else="warning" /> 
    <on-exit> 
     <evaluate expression="T(org.apache.log4j.Logger).getLogger('someLogger').info(requestParameters.canApprove)"/> 
    </on-exit> 
</decision-state> 

上述解决方案更是一个黑客的满足你的要求了。记录这种情况的“正确”方法是扩展FlowExecutionListenerAdapter,并监听当前的流程和决策状态ID“checkPermissin”,然后记录有关该流程的任何想要的内容,但会涉及flow.xml文件外的更多设置/编码。 (请参阅:Catch "dead" session in Spring webflow:该示例用于捕获异常,但可以轻松适用于记录流中的任何内容)

+0

谢谢,我会试一试。 – Razib