Agustin Lopez
Agustin Lopez

Reputation: 1365

Spring Webflow | Different validate method per transition

I currently have a Spring Webflow application that uses Webflow + Ajax.

I have a view-state called "A" that has several transitions.

<view-state id="A" model="myClass">
    <transition on="X1" .../>
    <transition on="X2" .../>
    <transition on="X3" .../>
</view-state>

The problem is that each transition should validate only a portion of "myClass" and not all. By default Spring Webflow has a single method to validate.

Basically what I need is to call a different validate method on each transition instead of having a single one.

Is this possible? Any ideas on how to do this?

Thanks in advance!!!

Upvotes: 1

Views: 2199

Answers (2)

laz
laz

Reputation: 28638

It is possible to use an attribute called validatorMethod to specify a particular method to call on the validator as described here. Here is a modified example from the Javadoc showing how do do this:

<view-state id="displayCriteria">
    <on-render>
        <evaluate expression="formAction.setupForm"/>
    </on-render>
    <transition on="search" to="executeSearch">
        <evaluate expression="formAction.bindAndValidate">
            <attribute name="validatorMethod" value="validateSearchCriteria"/>
        </evaluate>
    </transition>
</view-state>

This is assuming that the validator defined for searchFormAction has a method called validateSearchCriteria.

Upvotes: 1

tarts
tarts

Reputation: 46

Why not use one ValidationClass for view state? You can get the event that triggert the validation by calling

public String getUserEvent();

on the ValidationContext. Then, depending on the result do whatever you want to validate.

Upvotes: 3

Related Questions