I am starting a new Spring-MVC project. Validation is a important feature in any project. This way, i have seen many approachs as follows:
- Spring Validator interface
It sounds like a Struts 1.x validation. In my opinion, it is not agile.
- Commons Validator
I think it is better than Validator interface
- Annotation based bean validation (Spring modules)
It appears to be agile, but i do not know whether it does support for collection-based property
So, what’s the most AGILE APPROACH to validate Spring-MVC command in your opinion ? And why ? Consider many features like collection-based property, custom validation etc. If you know/use another approach in Spring-MVC, feel free to share it.
regards,
“Agile” means different things to different people 🙂
That said, Hibernate Validator is very convenient if you’re using Hibernate as ORM because it allows you to specify your constraints ONCE and have (some of) them propagated to database, work in your business layer and work in your UI layer. Additionally, 4.0 beta implements JSR 303 which most likely will be the standard approach to validation going forward.
Validator 3.1 does have certain issues with automatically validating constraints within collections of elements, but it’s reasonably easy to patch and / or work around (been there, done that, works perfectly now). Haven’t migrated to 4.0 beta yet, so I don’t know whether that was fixed.
It’s definitely extensible – you can easily write your own constraints.