Archive for July, 2008

Spring WebFlow - Passing Objects Between Parent Flow and Subflows

Wednesday, July 16th, 2008

While I was implementing web application using Spring WebFlow, I came to the point where i wanted to pass object created in the subflow to its parent flow.
I looked at the WebFlow documentation, and forums and blogs as well, and it seems that there is a bit of confusion with the webflow configuration of input and output parameters.
So here is what i have done to make it work:

If you want to pass object from subflow to its parent flow, you should declare it as output parameter in the end state of the subflow:

    <end-state id="endUpload" view="endupload" >
        <output-mapper>
            <mapping source="${flowScope.subflowResult}" target="subflowResult"/>
        </output-mapper>
    </end-state>

Note that the source argument is the parameter value as it is referenced in current flow (subflow), including the scope qualifier. Target is the text value, which will be the key in the generic parameters map that is transfered between subflow and its parent.

In the parent flow, you must declare output-mapper in the subflow-state section:

   <subflow-state id="uploadFile" flow="upload-flow">
        <attribute-mapper>
            <output-mapper>
                <mapping source="${subflowResult}" target="flowScope.result"/>
            </output-mapper>
        </attribute-mapper>
        <transition on="endUpload" to="startPublication"/>
    </subflow-state>

Now there is one very important difference in the output mapper: the source parameter is now the text, defining the key in the generic parameter map transfered from subflow, and the source is the the parameter name in the current flow (now parent flow) - including the scope qualifier.

And thats it!

If you want to do the oposite, pass the object as a parameter from the parent flow to the subflow, you will do similiar thing, only this time you will be dealing with input-mappers:
In parent flow definition, you will add input-mapper to the subflow-state definition:

<subflow-state id="transition" flow="workflow-flow">
        <attribute-mapper>
            <input-mapper/>
                <mapping source="flowScope.parentFlowParameter" target="parentFlowParameter"/>
            </input-mapper>
        </attribute-mapper>
        <transition on="done" to="done"/>
    </subflow-state>

And it the subflow, input mapper is needed at the beginning of the flow definition file:

<input-mapper/>
        <mapping source="parentFlowParameter" target="flowScope.myparameter"/>
</input-mapper>

I hope this will help some of you dealing with the same problem.

Variety Club on Rails

Monday, July 7th, 2008

I was tasked to provide additional functionality to the Variety Club site administrative suite. The additional functionality includes an online booking system for events using Google Checkout as the payment service provider and help volunteers manage these bookings and event attendees.
(more…)