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
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.
1. Confusing case
In Webflow there are cases where <decision-state> can be used in a similar fashion as <action-state>. The documentation shows that the below two expressions are interchangable.
<action-state id="moreAnswersNeeded">
<evaluate expression="interview.moreAnswersNeeded()" />
<transition on="yes" to="answerQuestions" />
<transition on="no" to="finish" />
</action-state>
and:
<decision-state id="moreAnswersNeeded">
<if test="interview.moreAnswersNeeded()" then="answerQuestions" else="finish" />
</decision-state>
2. When to use what?
Given that <decision-state> can handle only subset of what <action-state> handles - we should start from the former when considering two candidates.
Hope this helps.
you could use lambda condition
example: x = y ? "true result" : "false result"
<view-state id="viewname">
<on-entry>
<evaluate expression="flowScope.varx == x ? Bean.somethingX : Bean.somethingY " result="flowScope.varResult" />
</on-entry>
</view-state>
remember condition
They're very similar. You could write any decision state as an action state. Decision state just provides a convenient, concise syntax for conditional transitions (using the if
element). If I only need to evaluate one expression and transition depending on the outcome, I use a decision state. Otherwise (eg., if I have multiple expressions to evaluate), I use an action state.
HTH
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With