Tuesday, June 24, 2008

Spring Web Flow 2.0 Subflows

I have a simple subflow working with Spring Web Flow 2.0. It also has success messages and validation controlled by the flow. The example builds on Simple Spring Web Flow Webapp by adding an address subflow to the person flow along with displaying a message resource after a successful save. Validation for the flow and subflow are handled automatically by Spring Web Flow. The person flow uses a bean, personValidator, named to match the flow. The address flow has a method, 'validateAddressForm(MessageContext context)', in the Address class that matches the id of the view-state it should be called for


The subflow was a little bit of work. It's pretty straightfoward, but I wasn't used to reading the error messages from Web Flow showing all the scope variables. Also, I couldn't find a specific example doing a subflow for Spring Web Flow 2.0. Basically the input needs to be configured in the subflow-state and then again at the beginning of the subflow, and the output needs to be configured the same way.




Excerpt from Person Flow

<subflow-state id="address" subflow="address">
    <input name="id" value="addressId"/>
    <input name="person" value="person"/>
    
    <output name="address" />
    
    <transition on="saveAddress" to="personForm">
        <evaluate expression="personDao.saveAddress(id, address)" result="flowScope.person" />
        
        <set name="flashScope.statusMessageKey" value="'address.form.msg.success'" />
    </transition>
    <transition on="cancelAddress" to="personForm" />
</subflow-state>

Excerpt from Address Subflow

    <input name="id" />
    <input name="person" />

...

    <end-state id="saveAddress">
        <output name="address" value="address"/>
    </end-state>

No comments: