Spring Webflow, return to main flow from any sub-flow

fsonmezay picture fsonmezay · Apr 27, 2011 · Viewed 10.8k times · Source

I'm trying to return to my main flow in spring, from any of my subflows just by clicking a button.

when I use <end-state> it just goes to the previous flow, which is also a sub-flow in the application.

Any ideas?

Answer

David picture David · May 4, 2011

You just need the appropriate transitions in each subflow-state in the calling flow to do what you want. The end-state id in your subflow is what will be used as the event id you can transition on in your calling flow.

A subflow can be thought of as a branch of execution. So when your subflow is finished, control is returned back to the calling flow. Think of your end-state as a return statement (and the id attribute as the value returned -- you can also set output attributes but that is not important here).

When your subflow terminates, control is returned backed to the calling flow. The calling flow should define a transition that determines how to handle this event. The event id you will see is the id of the end-state in your subflow.

So in your subflow if you have the following end-state:

<end-state id="back"/>

You can then handle this transition in the flow that called the subflow:

<subflow-state id="do-some-sub" flow="some-sub">
    < ... input variables, expressions, etc ... />
    <transition on="back" to="some-state"/>
</subflow-state>

Note that some-state here can also be an end-state. Your situation sounds like you have a main flow that calls a subflow which in turn calls another subflow. So you would want some-state to be an end-state, which would then be handled by its calling flow (in your case the "main" flow).