问题描述
我正在使用spring web flow处理Web应用程序。当我正在处理一个 flow.xml
文件时,我得到了一个像这样的决定状态 -
I am working on a web application with spring web flow. While I am working on a flow.xml
file I have get a decision state on it like this -
<decision-state id="checkPermissin">
<if test="requestParameters.canApprove" then="approve" else="warning" />
</decision-state>
当请求到达 flow.xml
然后从中获取请求参数 canApprove
并测试它是真还是假。然后它进入批准
或警告
状态。
When a request comes to the flow.xml
then it get the request parameter canApprove
from it and test whether it is true or false. Then it goes to the either of approve
or warning
state.
我的问题是 - 我可以从 flow.xml
文件中记录/打印 canApprove
的状态吗?
My question is - can I log/print the status of canApprove
from the flow.xml
file?
推荐答案
您可以在决策状态的末尾添加一个退出标签并调用任何服务方法,spring bean或类路径上的静态方法。
You can add an on-exit tag to the end of the 'decision-state' and call any service methods, spring beans, or static methods on the classpath.
试试这个(未经测试):
Try this (untested):
<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并监听当前的流+决策状态IDcheckPermissin,然后记录您对该流的任何需求,但它将涉及flow.xml文件之外的更多设置/编码。 (请参阅::示例用于捕获异常但可以轻松地进行调整以记录流中的任何内容)
The above solution is more of a hack to fulfill what you are asking for. The "proper" way to log this is to extend a FlowExecutionListenerAdapter and to listen for your current flow + decision-state id "checkPermissin" then log whatever you desire about that flow but it would involve more setup/coding outside the flow.xml file. (see: Catch "dead" session in Spring webflow: the example is for catching exceptions but can easily be adapted for logging anything in a flow)
这篇关于从flow.xml打印日志的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!