【问题标题】:Pass reference attribute to action-state evaluate in spring webflow在spring webflow中将引用属性传递给动作状态评估
【发布时间】:2014-09-07 00:58:03
【问题描述】:

我正在尝试将参数传递给 Spring WebFlow 中的评估标签

<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") 

它返回字符串“flowScope.serviceInput”,而不是我之前在流中设置的 flowScope.serviceInput 的值,处于另一个状态。

我可以像这样在输入时传递参考值:

<action-state id="some action">
    <on-entry>
        <set name="flowScope.someName" value="flowScope.someOtherParam + ' anything!!'" type="java.lang.String"/>
</on-entry>

为什么我在设置属性时不能这样做?

解决方法不起作用,因为我们正试图以这种方式生成流。

谢谢!

【问题讨论】:

  • 您能否详细说明“它返回字符串“flowScope.serviceInput”而不是该表达式的值。”您希望评估在您的场景中执行什么?
  • @Prasad 我需要 .getAttributes().get("x") 来返回 flowScope.serviceInput 变量的值,我之前已将其设置为流的另一种状态,而不是字符串“flowScope.serviceInput”

标签: java spring spring-webflow


【解决方案1】:

如果我正确理解您的问题,那么您可以通过以下方式获取 flowScope.serviceInput 的值:

    RequestContextHolder.getRequestContext().getFlowScope().get("serviceInput")

在 Set 表达式中,值是根据 requestContext 范围的变量值对评估的。

在评估表达式中,表达式在 requestContext 中被评估(不是属性值)。因此,不会在 requestContext 范围的变量值对中查找属性值,但会按照流定义中的指定进行捕获。这就是原因,您为评估属性获得值“flowScope.serviceInput”,但设置其中包含的值。

但是你可以尝试使用 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.

【讨论】:

  • 谢谢,EL 解决方案符合需求。直到现在我还没有配置 EL,但这是另一个问题。再次感谢。
猜你喜欢
  • 1970-01-01
  • 2012-02-13
  • 2016-11-08
  • 1970-01-01
  • 2012-08-13
  • 1970-01-01
  • 1970-01-01
  • 2014-07-23
  • 2011-04-15
相关资源
最近更新 更多