Announcement Announcement Module
Collapse
No announcement yet.
<on-exit> and exception handling Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • <on-exit> and exception handling

    Let's say that I have a state that looks a little something like this:

    Code:
    <view-state id="A">
      <transition on="condition1" to="B" />
      <transition on="condition2" to="C" />
      <transition on="condition3" to="D" />
      <on-exit>
        <evaluate expression="someService.someAction()"/>      
      </on-exit>
    </view-state>
    Here I have a state that could end up transitioning to one of 3 other states. But regardless of where I head off to next, I need to always invoke someService.someAction()...that's why it's in <on-exit>.

    Fine...but what if someService.someAction() throws an exception? In that case I'd like to transition to "E"...so I change the state to this:

    Code:
    <view-state id="A">
      <transition on="condition1" to="B" />
      <transition on="condition2" to="C" />
      <transition on="condition3" to="D" />
      <transition on-exception="SomeException" to "E" />
      <on-exit>
        <evaluate expression="someService.someAction()"/>      
      </on-exit>
    </view-state>
    And this is where it all goes pear-shaped. As I transition away from "A", an exception is thrown from someService.someAction(). That triggers the on-exception transition...which is a transition away from "A", which means that the <on-exit> block is executed. someService.someAction() still throws an exception, which triggers the on-exception transition...which is a transition away from "A", which means...

    You get the picture.

    I read elsewhere that it is recommended to let exceptions be handled in the service and to have the service return an event for SWF to transition from. I agree with that...but not sure that it helps me here because I'd end up with the same scenario, only without the exceptions.

    Any idea how I can make this work?
    Last edited by habuma; Oct 28th, 2009, 02:47 PM.

  • #2
    It's redundant, but can you put your on-exit expression inside each of the transitions instead? This should let your on-exception transition work properly.

    Comment


    • #3
      That would work except that I left out one little detail (for simplicity's sake...I didn't think it would matter at the time)...

      Some of those transitions are defined in a parent state and are inherited by a handful of other states. The following snippet better illustrates the scenario I'm looking at:

      Code:
      <view-state id="#SOME_SECTION">
        <transition on="condition2" to="C" />
        <transition on="condition3" to="D" />
      </view-state>
      
      <view-state id="A" parent="#SOME_SECTION>
        <transition on="condition1" to="B" />
      
        <transition on-exception="SomeException" to "E" />
        <on-exit>
          <evaluate expression="someService.someAction()"/>      
        </on-exit>
      </view-state>
      
      <view-state id="Z" parent="#SOME_SECTION>
        <transition on="condition1" to="B" />
      
        <transition on-exception="SomeException" to "E" />
      </view-state>
      Here, I need to call someService.someAction() whenever/however I transition away from "A". But I do *NOT* need to call it when transitioning away from "Z".

      I suppose that I could create multiple parents (one with and one without the on-exit), but that is a bit uglier than I would've liked.

      Comment


      • #4
        Remember, transition elements are merged, they don't override.

        You can redefine all of the inherited transitions in state "A" and place your evaluate expression in each of the transitions.

        Comment

        Working...
        X