Back Forum Reply New

Multiple actions in action-state

Hello everyone

I just was wondering how to overcome the fact that the first Event that matches a transition criteria executes the transition.

Lets assume I have an action-state with more than one action. If action1 returns quot;successquot;, the transition to quot;homequot; will be applied and action2 is not executed.

Code:
lt;start-state idref=quot;setupFlowquot;/gt;

lt;action-state id=quot;setupFlowquot;gt;
lt;action bean=quot;myActionsquot; method=quot;action1quot; /gt;
lt;action bean=quot;myActionsquot; method=quot;action2quot; /gt;
lt;transition on=quot;successquot; to=quot;homequot; /gt;
lt;transition on=quot;errorquot; to=quot;errorpagequot; /gt;
lt;/action-stategt;
Currently I simply return quot;yesquot; in action1 (and quot;errorquot; in case of an error) so that action2 is also executed.

Would such a construct make sense?

Code:
lt;transition on-last=quot;successquot; to=quot;homequot; /gt;
This would only execute the transition if the last action returns quot;successquot;. This would let the user just work with the standard events so that (normally) no custom Events have to be introduced.

What do you think? Other proposals how to handle this issue?Regards

James

This is exactly what 'named actions' are for, e.g. using the quot;namequot; attribute of an action.

Check the SWF XSD and reference manual for more info on named actions:

An optional name qualifier for this action. When specified this action will
qualify execution result event identifiers by this name. For example, if this
action is named quot;placeOrderquot; and signals a quot;successquot; result event after execution,
the fully qualified result event the flow can respond to would be quot;placeOrder.successquot;.
lt;brgt;
This can be used to execute actions in an ordered chain, where the flow responds
to the the last action result in the chain:
lt;pregt;
amp;lt;action-state id=quot;setupFormquot;amp;gt;
amp;lt;action name=quot;setupFormquot; bean=quot;formActionquot; method=quot;setupFormquot;/amp;gt;
amp;lt;action name=quot;loadReferenceDataquot; bean=quot;formActionquot; method=quot;loadReferenceDataquot;/amp;gt;
amp;lt;transition on=quot;loadReferenceData.successquot; to=quot;displayFormquot;amp;gt;
amp;lt;/action-stateamp;gt;
lt;/pregt;
... will execute 'setupForm' followed by 'loadRefenceData', then transition the flow to
the 'displayForm' state on a successful 'loadReferenceData' invocation.
lt;brgt;
An action with a name is often referred to as a quot;named actionquot;.

Erwin

I just thought that there must be a more elegant way to handle this. :-)

Thanks for the quick response.James

Ok. In this case I'm able to trigger a transition on a specific named action only.
But the transition in case of an error cannot be handled generally then.

It would be nice if the transition on=quot;errorquot; is executed, if any of the actions returns an quot;errorquot; event. Maybe it would be feasible that a transition could be defined like this: lt;transition on=quot;*.errorquot; to=quot;errorpagequot; /gt;James

This is already possible. Remember that the quot;onquot; attribute of a transition can be an OGNL expression, so you can have:Code:
lt;transition on=quot;${#result.endsWith('error')}quot; to=quot;errorPagequot;/gt;
The quot;#resultquot; is an alias for the last event that occured, i.e. it's basically '${lastEvent.id}'.

Erwin

Thank you for this hint. I did not even notice that OGNL can be used to define state matching criteria. It's perfect now.
¥
Back Forum Reply New