Search code examples
springspring-webflowspring-webflow-2

Webflow stepping back and forth between view states


I'm learning to use Spring Webflow. I want to create a from which is working like an old school installer. At every view-state i have a next and a back button.

My question would be that is it possible to programmatically determine which is the next view-state or the one before the current one? So I can provide that information to my buttons?


Solution

  • Yes you can do this but you would have to EXPLICITLY predefine each transition/jump within that specific viewstate inside the flow xml file.

    For example:

    (assume we have the following view-states defined in our webflow file)

    <view-state id="viewStateA"> 
         <transition on="gotoB" to="viewStateB"/>
         <transition on="gotoC" to="viewStateC"/>
    </view-state> 
    
    <view-state id="viewStateB">
         <transition on="gotoA" to="viewStateA"/>
         <transition on="gotoC" to="viewStateC"/>
    </view-state> 
    
    <view-state id="viewStateC">
         <transition on="gotoA" to="viewStateA"/>
         <transition on="gotoB" to="viewStateB"/>
    </view-state>
    

    So if you're currently in viewStateC. You can ONLY transition/goto either viewStateA or viewStateB because you predefined them as possible transitions inside (from) viewStateC.

    ...

    And to trigger any transition all you have to do is make a HTTP-GET request that looks like this passing the 'on' value for the specific transition desired as the '_eventId' like this:

    ${flowExecutionUrl}?_eventId=gotoA
    

    In this case the the transition 'gotoA' will be triggered which in turn will take us back to 'viewStateA'

    So to answer your question... aslong as you know the transition 'on' name and it is predefined within that view-state you can programmatically trigger/goto which ever view-state/action-state/decision-state you desire by making the HTTP-GET request to the desired transition.