Ionut Bilica
Ionut Bilica

Reputation: 434

Pass reference attribute to action-state evaluate in spring webflow

I'm trying to pass a parameter to an evaluate tag in a 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>

In the SomeService bean, when I get retrieve the x parameter like this:

RequestContextHolder.getRequestContext().getAttributes().get("x") 

it returns the String "flowScope.serviceInput" instead of the value of the flowScope.serviceInput which I've set previously in the flow, in another state.

I can pass reference values on on-entry like this:

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

Why can't I do it when setting an attribute to an evaluate?

Workarounds would not work because we're trying to generate flows this way.

Thanks!

Upvotes: 1

Views: 2292

Answers (1)

Prasad
Prasad

Reputation: 3795

If I understand your question correctly, then you can get value of flowScope.serviceInput by:

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

In Set expression, value is evaluated against requestContext scoped variable-value pairs.

In evaluate expression also, expression is evaluated(not the attribute value) in requestContext. So there will not be a lookup for attribute value in requestContext scoped variable-value pairs but it is captured as specified in flow definition. This is the reason, you get value as "flowScope.serviceInput" for evaluate attribute but for set the value contained in it.

But you can try using EL to get it as:

    <attribute name="x" value="#{flowScope.serviceInput}"/> 
    for SWF version > 2.1 

or with

    <attribute name="x" value="${flowScope.serviceInput}"/> 
    for SWF version < 2.1 where ever you are setting this attribute value.

Upvotes: 1

Related Questions