Search code examples
javaspringpropertiesspring-webflow-2

Dynamic Transitions in Spring WebFlow


Does anybody know if it's possible to define dynamic transitions in a Spring Web Flow definition?

Example 1 - using a properties file:

<action-state id="createSubscription" >
    <evaluate expression="myvar" />
    <transition on="$[test.result.valid]" to="subscribeUser-successResponse" />
    <transition                               to="subscribeUser-exceptionResponse" />
</action-state>

Example 2 - using the value of the variable itself:

<action-state id="createSubscription" >
    <evaluate expression="myvar" />
    <transition to="$[myvar]" />
</action-state>

It's not mandatory, but could help to design more generic flows.

Thanks in advance to everyone.


Solution

  • You can do definitely do for transition "to". Suppose flow xml has some action and view state as:

        <action-state id="createSubscription">
            <evaluate expression="myAction.prepareNextState(flowScope.formBean)"/>
            <transition to="${flowScope.formBean.displayNextState}">
        </action-state>
    
        <view-state id="someView" view="someView" model="formBean">
            ...
        </view-state>
    

    and myAction class with prepareNextState method is as:

        public class MyAction implements Serializable{
            ....
            public void prepareNextState(FormBean formBean){
                //displayNextState is a String field in FormBean                
                formBean.setDisplayNextState("someView");
            }
            ....
        }
    

    This way we can define generic transitions for transition "to".