Spring MVC form validation

I've been playing with Spring MVC and adding Commons Validator support for both client and server side form validation.

I'm always surprised (although I shouldn't be) by the number of web apps I run across in the corporate world that only do client side validation or do server side validation and then force you to hit the back button. Anyhow, the process was relatively painless and I had support added to my project and working in about 30 minutes. Adding validation to new forms in the project is a matter of minutes now. I followed Matt's tutorial Using Commons Validator with Spring Redux.

Now I have my controller use Spring's BeanValidator and can simply add my validation to my WEB-INF/classes/validation.xml file and voila, client and server side validation. I also like that Spring lets you use your model objects as MVC command objects. So on a basic detail page I only need to create my controller with a few lines of code, a JSP page, and edit my validation.xml file.

Next up I'm hoping to spend some time this weekend and look at Tapestry to get a better feeling for it. I just picked up Tapestry in Action which is proving to be an interesting read so far.

This entry was posted in Java. Bookmark the permalink.

One Response to Spring MVC form validation

  1. paul says:

    i also wanna share a very good source of spring validation technique. you can find it here:

    http://www.adobocode.com/spring/adding-validation-to-spring-forms

    hope you’ll learn from it too.

Leave a Reply

Your email address will not be published. Required fields are marked *