9

I have an action-state that evaluates an expression and then transitions to various other states depending on the result. One of the result states is a subflow-state that hands control to another flow, example;

<action-state id="doWork">
    <evaluate expression="someAction.doWork(someInput)" />
 <transition on="WORKSUCCESS" to="workSuccess" />
 <transition on="WORKFAIL" to="fixFail" />
</action-state>

<subflow-state id="fixFail" subflow="someOtherPlace/someOtherWorkToFixFail">
    <input name="someNumber" value="1" type="java.lang.Integer" />
    <transition on="finish" to="workSuccess" />
</subflow-state>

As you can see I can pass an input into the subflow via the input tag but my question is how can I specify and pass additional inputs that I want present if and only if the subflow-state is being called from the transition WORKFAIL? Assume the subflow-state "fixFail" can be called from other action-states.

I've tried things similar to the following with no effect;

<action-state id="doWork">
    <evaluate expression="someAction.doWork(someInput)" />
 <transition on="WORKSUCCESS" to="workSuccess" />
 <transition on="WORKFAIL" to="fixFail">
            <attribute name="newInput" value="3000" type="java.lang.Integer" />
    </transition>
</action-state>

<subflow-state id="fixFail" subflow="someOtherPlace/someOtherWorkToFixFail">
    <input name="someNumber" value="1" type="java.lang.Integer" />
    <input name="someNumber2" value="flowScope.newInput" type="java.lang.Integer" />
    <transition on="finish" to="workSuccess" />
</subflow-state>
skaffman
  • 398,947
  • 96
  • 818
  • 769
Nick Foote
  • 2,425
  • 9
  • 36
  • 47

1 Answers1

15

There are three ways you can do this. You can do it through the conversation, session or as attributes passed in.

  • ConversationScope: If a field is in the conversationScope the field is visible anywhere in that specific flow as well as that flow's subflows (and their transitions)

  • SessionScope: (Probably not what you want) Is visible to all flows and
    their subflows

Finally you can pass the field as an attribute into the subflow state for example

<subflow-state id="fixFail" subflow="someOtherPlace/someOtherWorkToFixFail">
    <input name="someNumber" value="1" type="java.lang.Integer" />
    <input name="someNumber2" value="flowScope.newInput" type="java.lang.Integer" />
    <transition on="finish" to="workSuccess" />
</subflow-state>

In your subflow's xml

<?xml version="1.0" encoding="UTF-8"?>
<flow>
    <input name="someNumber"/>
    <input name="someNumber2"/>
    ...
</flow>

In this example someNumber and someNumber two are passed in as attributes to your subflow. In which you can evaluate them as ${someNumber}

Edit:

This is to address your comment question. If you wanted to set a variable in the conversation scope on a specific transition you can do:

<transition on="WORKFAIL" to="fixFail" >
  <set name="conversationScope.someVariable" value="Hello World"/>
</transition>

Then in your jsp

${someVariable}  <!-- This will print out 'Hello World' -->
John Vint
  • 39,695
  • 7
  • 78
  • 108
  • Hmmm the conversationScope sounds like what I want in this case I think. I agree the session is what I want as the user repeat these flows once they finished the first time and any session attributes would remain wouldn't they? Where as conversation scoped attributes would disappear when the main flow finishes and wouldn't be present if the user entered the main flow for a second time, correct? Is there a way to add to the conversationScope in the transition on="WORKFAIL"? I would like to keep it in the xml/jsps rather than add to the Java code of the action. – Nick Foote Jan 06 '11 at 11:39
  • Cheers that works a treat, so obvious when you see it, I was trying all sorts of things like ${converationScope.someVariable} in the jsp!! – Nick Foote Jan 06 '11 at 15:04