Page 1 of 2 12 LastLast
Results 1 to 10 of 11

Thread: Trying to understand end-state in subflows

  1. #1
    Join Date
    Sep 2008
    Location
    Denmark
    Posts
    18

    Default Trying to understand end-state in subflows

    I am rather new to SWF, and I'm trying to figure out how to use subflows.
    I got something working, but I'm not sure I understand the end-state part of a subflow completely, so I hope someone can clarify it for me.

    Here is my example:
    The masterflow:
    Code:
    	<view-state id="bookList">
    		<transition on="toDetails" to="bookDetail" />
    	</view-state>
    	<view-state id="bookDetail">
    		<transition on="toList" to="bookList"></transition>
    		<transition on="showAuthor" to="showAuthor"></transition>
    	</view-state>
    	<subflow-state id="showAuthor" subflow="author" >
    		<transition on="endSubFlow" to="bookDetail" ></transition>
    	</subflow-state>
    and the Subflow (which also can be used a a Masterflow in some other context)
    Code:
    	<view-state id="author">
    		<transition on="showAuthorSelected" >
    			<evaluate expression="authorController.findAuthor(requestParameters.authorId)" result="viewScope.selectedAuthor"></evaluate>
    		</transition>
    		<transition on="showBookDetail" to="endSubFlow" ></transition>
    	</view-state>
    	<end-state id="endSubFlow"></end-state>
    And the things that I'm not sure of:
    In the subflow definition in the masterflow - do I have to define a transition for every end-state that the subflow contains? What exactly happens if I don't do that? Say that the subflow could also contains an end-state like
    <end-state id="confuseMe"/>, but the masterflow does not have a transition for that?

    And if my end-state in the subflow is defined with a view like this
    <end-state id="endSubFlow" view="externalRedirect:some-URL"></end-state>
    will the externalRedirect occur when the flow is used as a subflow, or will it just return to the masterflow, which already have another definition of what to do when "endSubFlow" is returned?

    What I'm really trying to figure out is how to reuse flows both in the context of it being the Masterflow, but also working as a subflow. So the transitions in the flow might depend on whether the flow is being executed as a master- or subflow.

    Does it make sense at all??

  2. #2
    Join Date
    Sep 2004
    Posts
    602

    Default

    Quote Originally Posted by frydenholm View Post
    I am rather new to SWF, and I'm trying to figure out how to use subflows.
    I got something working, but I'm not sure I understand the end-state part of a subflow completely, so I hope someone can clarify it for me.
    My understanding of end-states (which may not be correct!) is that they are really nothing more than the equivalent of a "return" in a method. They have ids on them because in a sub-flow you might want to end the sub-flow in one of a number of different says, but I dont think (element of slight doubt) here, that the id of the end-state you end the flow on has anything to do with transitions in the flow calling the sub-flow.

    Just think of it as a method call in Java - you call it, it returns, from where it returned and why you don't know or care. If you do want to signal something to the calling flow you can output something - see section 2.7.2 of the webflow 2.0.4 reference.

  3. #3
    Join Date
    Aug 2004
    Location
    Melbourne, FL
    Posts
    2,794

    Default

    The id of an end-state reached in a terminating subflow is used as the id of the outcome event that is handled by the resuming parent flow. This allows the parent to respond to different subflow outcomes in different ways. Is this not clear in the reference manual?
    Keith Donald
    Core Spring Development Team

  4. #4
    Join Date
    Sep 2004
    Posts
    602

    Default

    Quote Originally Posted by Keith Donald View Post
    The id of an end-state reached in a terminating subflow is used as the id of the outcome event that is handled by the resuming parent flow. This allows the parent to respond to different subflow outcomes in different ways. Is this not clear in the reference manual?
    Mea culpa.

    Honest answer, could be a bit clearer.

    Section 2.9.1. mentions flows returning with specific outcomes.
    Section 2.5.4. end-state mentions how to define outcomes.

    section 2.9.1 could be amended to explain that when an end state with a specific id is reached, this generates an outcome that can be used as a transition in the sub-flow element. I'll admit all the information is there, but you have to jump around the manual a bit to get the big picture.

  5. #5
    Join Date
    Sep 2008
    Location
    Denmark
    Posts
    18

    Default

    In Checkpoint: calling subflows in section 2.9, I think it could make it more clear to me, if the flow createGuest, which is used as a subflow, was shown next to the booking flow.

    That will make it easier to see how the end-state id's in createGuest matches the transitions in the booking flows subflow-state.

    And I'm still not sure what happens if the end-state in createGuest is defined like:
    <end-state id="guestCreated" view="flowRedirect:someOtherFlow">

    If the "createGuest" flow is used a normal flow, it will redirect to "someOtherFlow" when the guest is created.

    But if it is used as a subflow, will view="flowRedirect:someOtherFlow" just be ignored, and instead return to the subflow-state and do the
    <transition on="guestCreated" to="reviewBooking">
    <evaluate expression="booking.guests.add(currentEvent.attrib utes.guest)" />
    </transition>

  6. #6
    Join Date
    Aug 2004
    Location
    Melbourne, FL
    Posts
    2,794

    Default

    Yes the end-state view attribute to generate a final response is only relavent when the flow is used as a top-level flow. It's ignored when the flow is called as a subflow.
    Keith Donald
    Core Spring Development Team

  7. #7
    Join Date
    Sep 2008
    Location
    Denmark
    Posts
    18

    Thumbs up Thanks

    Thanks for the answers!

    This was not completely clear to me from the reference manual (or maybe I just missed something)

  8. #8
    Join Date
    Nov 2007
    Posts
    9

    Default So the id of the sub-flow end state is what is meant by the outcome

    It is not at all clear in the manual (2.5.4).

  9. #9
    Join Date
    Nov 2006
    Location
    Boston, MA
    Posts
    303

    Default

    Quote Originally Posted by grelf View Post
    It is not at all clear in the manual (2.5.4).
    I haven't looked at that part of the manual in a while, but it was pretty clear to me back when I first started using SWF 1.0.5: each end state ID of a sub-flow may be used as a transition event ID in the parent flow.

    A sub-flow, just like any type of subroutine is an abstraction that should be viewed as a single step by the caller. To help you grasp the idea better, think of a sub-flow as a single state - from the standpoint of the parent flow. That state (your sub-flow) may result in one or more events (sub-flow's end states.) On each resulting event, you may define a transition. That's it. Ve-e-e-ry simple.

    That said, perhaps, the manual should contain a similar clarification...

  10. #10
    Join Date
    Nov 2007
    Posts
    9

    Default Terminology

    The Spring manuals are, on the whole, very good. Where they go wrong, as in the present example, is inconsistent use of terms. Associating the "outcome" of a flow with an event id must have seemed natural to the author but was extremely unobvious to this reader. Instead I thought it meant something to do with <output> elements that a flow can define. I spent many, many frustrating hours going down that road.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •