New to Spring here, and after reading the reference docs the workflow to validate a simple web form isn’t popping out at me.
Could someone give me a beginners overview of how we go about form validation in Spring 3.0.3 (I’m using a mix of annotations and xml config in a webapp that I’m migrating now). Starting from the Controller, what happens?
For example: so far I think I understand that I should “bind” the form data to an object of my creation (say MyPerson for example), then create a Validation object that accepts MyPerson and uses ValidationUtils to perform the validation.
But that’s all very fuzzy in my head (especially the “binding” concept) and a step by step review of the workflow from someone who’s been through it before would help me be confident that I’m not missing or mis-interpreting any steps.
The method you are mentioning for validating forms is one of a few options you have available.
As well as the method you have suggested you may also want to investigate using JSR-303 annotations with an appropriate implementation (for example Hibernate Validator). There are a lot of example of how to accomplish this.
For the spring validation method your basic steps are:
@ModelAttributeannotation to bind the form data to your binding object@Autowiredto your controller) to perform validationHeres a simple example controller:
}