1

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!!!

Agustin Lopez
  • 1,355
  • 4
  • 18
  • 34

2 Answers2

3

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.

tarts
  • 46
  • 2
  • The ebflow Reference Guide writes: ValidationContext A ValidationContext allows you to obtain a MessageContext to record messages during validation. It also exposes information about the current user, such as the signaled userEvent and the current user's Principal identity. This information can be used to customize validation logic based on what button or link was activated in the UI, or who is authenticated. [link](http://static.springsource.org/spring-webflow/docs/2.0.x/reference/htmlsingle/spring-webflow-reference.html#view-validate) – tarts Nov 16 '11 at 15:21
  • This seems like it works. Thank you very much. I will test it and I will let you know if it does! – Agustin Lopez Nov 16 '11 at 17:01
1

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.

laz
  • 28,320
  • 5
  • 53
  • 50