Announcement Announcement Module
No announcement yet.
Action Vs Transition Page Title Module
Move Remove Collapse
Conversation Detail Module
  • Filter
  • Time
  • Show
Clear All
new posts

  • Action Vs Transition

    Hello All
    I am new to SWF and i am trying to understand the difference between an actions and transitions. When i look at the examples i can see that they are used interchangeably. other than the decision states in actions state i can use a transition in its place by using some pojos and use evaluate expression attribute. thanks.

  • #2
    Are you familiar with state machines? If not, google it, and maybe learn about state diagrams as well.

    The only way to go between states in state machines (and SWF) is through transitions. If you're transitioning from a view-state, then the transition is likely invoked through a button or form submission. When transitioning from any other state, the transition is likely triggered through the evaluation of some expression (using the evaluate action), or is an unconditional transition (a transition without an "on" attribute). Some transitions do not transition from the state (usually found in view-states), but most transition to other states.

    Actions come in a few types (set, evaluate, render) and can appear in many places. Set actions typically set values on attributes, or set attributes into scope. Render actions are used to tell SWF which sections of the page to update with AJAX. Evaluate actions typically evaluate some expression or make a method call on an object. Actions can be triggered at the start or end of a flow, on entry and exit of states, on render of a view-state, and within transitions.

    My guess is there are probably two cases which might be confusing you. The first uses an action-state, which uses the result of an evaluate action to drive a transitions to a different state:

    <action-state id="myAction">
      <evaluate expression="myBean.doStuff()"/>
      <transition on="success" to="theNextState"/>
      <transition on="failure" to="aPreviousState"/>
    The outcome of the doStuff() invocation (in this case, a String) is compared to the events handled by the transitions. If the returned String is "success", it invokes the first transition, and if it's "failure", the second. Comparisons to invoke transitions are usually done with Strings, ints, and booleans.

    The second case is programmatic validation of a form submission. It's worth pointing out that when an evaluate action appears inside a transition, that if the evaluation is false, then the transition is cancelled and the remaining actions are not performed:

    <view-state id="myView">
      <transition on="submit" to="nextState">
        <evaluate expression="myForm.validate()"/>
    The transition event can be whatever you want, as long as you're consistant between what's on your page and what's in your flow. The expression to evaluate can be just about anything, it's just a method call on some object in scope.


    • #3
      Thank you very much for the reply