Reputation: 1315
I am new to Spring MVC. I came across the validations provided by hibernate-validator and Spring tag. I have done only a little bit of web programming (Perl) where I had done Javascript validations on the front-end combined with back-end validations to keep out invalid data.
Seems to me that with the validations provided by Spring MVC, one could do validations only on the back-end. What would be different is that all validations would have to wait until the user submits the form. Also, since there would be no front-end validations, performance could be an issue. What I am asking is what is the right approach to form validations while using Spring MVC.
Upvotes: 1
Views: 659
Reputation: 81970
Backend validation only does work. While validation only on the client does not work, because it is insecure.
But usability often becomes an issue with Backend validation due to the performance.
You can still validate on the fly on the backend, by calling your backend onBlur but now your application tightly couples frontend and backend together. Frameworks like JSF do this, and IMHO it is a really bad idea.
Some frameworks (also JSF) try to automate the validation on the frontend based on annotations in the backend. But this can only work as long as you stick to a limited set of prepared annotations, so again not a solution for the problem.
So I'd say: stick with the usual approach of having frontend validation based on javascript and backend validation with whatever tool you happen to use. Everything else is either severly limited or gets overly complicated fast.
Upvotes: 1
Reputation: 2906
Sry, but the "right approach" here, as for all (client/server) Validations, regardless of the programming language, the framework etc., is to rely on frontend and backend-Validation, because frontend-only is simply insecure (read here or here for more).
e.g. use for Frontend some JS/jQuery-plugin, for Backend SpringMVC/hibernate @Valid-Annotation with the corresponding checks at your entity. Use Ajax-calls or something similar if you don't want to wait until submit is pressed. Here is an example (untested )
Upvotes: 0