views:

417

answers:

4

In Asp.Net MVC 2.0, at least in the beta, you could decoration your model classes with data annotation attributes and enable client side validation that leverages that criteria defined in your model data annotation attibutes. Is there anything similar for Java Spring MVC 3.0?

Is it possible to inject a component into the response pipeline that can inspect the model's annotated properties and render client side validation logic to complement the server side validation logic that is invoked prior to the controller handling the request?

+2  A: 

Spring MVC is a fairly low level framework. It doesn't extend to doing client side validation.

There are other Java Web frameworks that do this such as Tapestry, Wicket and JSF (IceFaces, etc). These are what I tend to call "component frameworks".

cletus
+2  A: 

In Spring MVC 3.0 there's nothing like that at the moment.
As cletus said frameworks like Tapestry (ex), Wicket (ex) and others have some sort of Client Validation that uses JavaScript to validate forms etc.
You can write your own validation Jstl taglib maybe with the help of a JS Library (jQuery, ...) and Plugins like : jQuery Validation Plugin

edit: I've just found this: Mediawidget. Maybe it's worth having a look.
It says: "Metawidget reads Bean Validation annotations and generates forms with widgets that are pre-configured for minimum/maximum values, lengths etc."

Spring integration Link1, Link2

al nik
+3  A: 

Actually, there is something a little bit like it, based on the JSR-303 Bean Validation spec, which is now final and fully supported by Spring 3.0.

Recently, as part of Spring Webflow, Springsource has released Spring JS (javascript) which uses Dojo. You can use that for your client side validation. Check out this howto

Obviously, component-frameworks such as Wicket (like fraido mentioned) have better support for this kind of usecase. So if you have to implement a lot of similar usecases, that is probably a better fit for your project. However, if it is sporadic, Spring JS / Bean validation could be the way to go.

Hans Westerbeek
I used Spring JS and I've to say that it's very limited.
al nik
Yes it is, that's why I said in my answer that it is only a good choice if there is not *that* many usecases in his project that require extensive validation.
Hans Westerbeek
A: 

Ok, this is a variation on what's already been said, but one of the big strengths of Spring-MVC is its ability to integrate with other libraries, like the different JSF variations that do give client side validation.

mezmo