我正在尝试将参数传递给Spring WebFlow中的evaluate标记
<action-state id="activateOption">
<evaluate expression="someService.call()" result="flowScope.serviceResult" result-type="java.lang.String">
**<attribute name="x" value="flowScope.serviceInput"/>**
</evaluate>
<transition on="0" to="Stop_View"/>
</action-state>
在SomeService bean中,当我像这样检索x参数时:
RequestContextHolder.getRequestContext().getAttributes().get("x")
它返回String“flowScope.serviceInput”,而不是我之前在流程中设置的flowScope.serviceInput的值,在另一个状态。
我可以在on-entry上传递参考值,如下所示:
<action-state id="some action">
<on-entry>
<set name="flowScope.someName" value="flowScope.someOtherParam + ' anything!!'" type="java.lang.String"/>
</on-entry>
为评估设置属性时为什么不能这样做?
变通办法不起作用,因为我们试图以这种方式生成流程。
谢谢!
答案 0 :(得分:1)
如果我理解你的问题,那么你可以通过以下方式获得flowScope.serviceInput的值:
RequestContextHolder.getRequestContext().getFlowScope().get("serviceInput")
在Set表达式中,将根据requestContext范围的变量值对评估值。
在evaluate表达式中,还会在requestContext中计算表达式(而不是属性值)。因此,在requestContext范围的变量值对中不会查找属性值,但会按照流定义中的指定捕获它。这就是为什么你得到的价值是&#34; flowScope.serviceInput&#34; for evaluate属性,但用于设置其中包含的值。
但你可以尝试使用EL来实现它:
<attribute name="x" value="#{flowScope.serviceInput}"/>
for SWF version > 2.1
或
<attribute name="x" value="${flowScope.serviceInput}"/>
for SWF version < 2.1 where ever you are setting this attribute value.