Search code examples
spring-webflow

How to implement conditional transitions in Spring Webflow


Just getting the hang of Spring Webflow. I have some simple forms working and binding back and forth - very cool. One thing not obvious to me at the moment is how to dynamically launch a flow based on user input.

i.e. imagine a flow where the user chooses an option in the first screen, and based on the choice taken, different subflows can be initiated. In pseudo-terms something like the following pseudo-flow:

    <view-state id="selectService" model="serviceType">
            <transition on="proceed">
               <if "serviceType.selectedValue==1" to="subFlow1" />
               <if "serviceType.selectedValue==2" to="subFlow2" />
               <if "serviceType.selectedValue==3">
                      <if "serviceType.isValid==3" to="subFlow3" />
               </if>
               <default to="cancel" />
             </transition>
            <transition on="cancel" to="cancel" />
    </view-state>

I've trawled the examples, docs, stackoverflow and the spring forums but haven't seen this anywhere..


Solution

  • It is covered in Spring in Action 3, which is a great book for Spring development in my eyes.

    To answer your question here though, I think you are looking for the decision-state transition element. To get to user input, you should be able to use Spring Expression Language (SpEL) in the test attribute.