Spring Webflow - decision-state vs action-state

Johnathan Smith picture Johnathan Smith · Aug 16, 2012 · Viewed 25.2k times · Source

I am using Spring WebFlow 2 and I want to know the diff of decision-state vs action-state.

I am reading up and dont understand the diff of decision-state vs action-state. I understand that view-state will display a jsp for input but whats the diff of decision-state vs action-state?

why should I use decision-state over a action-state? why should I use a action-state over a decision-state?

Can someone shot some light on this

Answer

Ian Bishop picture Ian Bishop · Aug 16, 2012

Generally, decision-state is used exclusively for a boolean conditional. It's more clear and concise as to what it occurs.

For instance,

<decision-state id="myDecisionState">
    <if test="myBooleanFunction()" then="resultIsTrueState" else="resultIsFalseState" />
</decision-state>

This can be replicated using an action-state like so:

<action-state id="myActionState">
    <evaluate expression="myBooleanFunction()" />
    <transition on="yes" to="resultIsTrueState" />
    <transition on="no" to="resultIsFalseState" />
</action-state>

However, the difference is that action-state does not just operate on booleans - it can trigger transitions on String (string value), Boolean (yes/no), Enum (enum name) with any other result considered a success.

So, by contrast to a decision-state which actually has to decide something, an action-state can simply be used to execute some code.

<action-state id="myActionState">
    <evaluate expression="myFunction()" />
    <transition on="success" to="myNextState" />
</action-state>

I hope that clears stuff up.