Spring Webflow - FormAction.doValidate() isn't called when there is no validator configured

This post is relevant for the Spring Webflow 1.x users.

I have been breaking my head from 2-3 days over this problem and was able to crack it today.
I did some search on google and found that this is a open Bug on Spring Webflow (Spring Webflow 1.0.3 Bug SWF-397)
This bug has not been resolved since they can't do it in a 100% backwards compatible way. I found a workaround/solution so thought of sharing with other who are struggling on problem.

What is the issues?


The problem occurs when you have a FormAction bean configured in your application without a validator e.g.



class="example.spring.forms.OfferForm">



The spring framework code does a check for "if (getValidator() != null) " before making a call to doValidate() method and therefore doValidate method will not be called when we have configured the FormAction bean like above.

What is the workaround?

The workaround is simple and requires you to write a simple dummy validator class which does nothing. Below is a Sample dummy validation class you can use for your application.



package example.spring.validations;

import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.springframework.validation.Errors;
import org.springframework.validation.Validator;

/**
* @author swiki
*
*/
public class DummyValidation implements Validator {

public boolean supports(Class clazz)
{
return true;
}

public void validate(Object target, Errors errors)
{
return;
}

}



Now inject this dummy validator bean to all the form beans where you want your own doValidate method to be called. See the example bean config below



class="example.spring.forms.OfferForm">






Thats it! Your doValidate method should start getting called now as the "if (getValidator() != null) " condition will not fail.

Please don't forget to share, if you know of a better workaround for this.