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 issue?


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

 


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

 


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.

2 Post Comment

Anonymous said...

if you dont konw whether the code works properly or not,Why did you post it

Software Wikipedia said...

@Anonymous - Let me know what it the problem you are facing? I can try to help you. This code works and I have used it in live projects. If you found any issues please feel free to share and I will try to resolve.

Please don't forget to mention about the Spring webflow framework version you are using. As I mentioned this post of valid for Webflow 1.x version. If you are using 2.x you may need to read more details. The XML configs have changed significantly in webflow 2.x.

Post a Comment

Search Web......