Matt RaibleMatt Raible is a Web Architecture Consultant specializing in open source frameworks.

10+ YEARS


Over 10 years ago, I wrote my first blog post. Since then, I've authored books, had kids, traveled the world, found Trish and blogged about it all.

JSR 303 and JVM Web Framework Support

Emmanuel Bernard recently sent an email to the JSR 303 Experts Group about the next revision of the Bean Validation JSR (303). Rather than sending the proposed changes privately, he blogged about them. I left a comment with what I'd like to see:

+1 for Client-side validation. I'd love to see an API that web frameworks can hook into to add "required" to their tags for HTML5. Or some service that can be registered so the client can make Ajax requests to an API to see if an object is valid.

Emmanuel replied that most of the necessary API already exists for this, but frameworks have been slow to adopt it.

Hi Matt,

The sad thing is that the API is present on the Bean Validation side but presentation frameworks are slow to adopt it and use it :(

RichFaces 4 now has support for it but I wished more presentation frameworks had worked on the integration. If you can convince a few people or have access to a few people, feel free to send them by me :)

The integration API is described here. Let me know if you think some parts are missing or should be improved. We should definitely do some more buzz around it.

In the interest of generating more buzz around it, I decided to do some research and see what JVM Frameworks support JSR 303. Here's what I've come up with so far (in no particular order):

Struts 2 has an open issue, but doesn't seem to support JSR 303. Since I did a quick-n-dirty google search for most of these, I'm not sure if they support client-side JavaScript or HTML5's required. If you know of other JVM-based web frameworks that support JSR 303, please let me know in the comments.

Posted in Java at Mar 08 2011, 11:33:24 AM MST 4 Comments
Comments:

While not really a JVM based web framework, Flex thanks to GraniteDS does support Bean Validation as well.

http://www.graniteds.org/confluence/display/DOC/8.+Bean+Validation+%28JSR-303%29

Posted by Emmanuel Bernard on March 08, 2011 at 01:30 PM MST #

Hi Matt,

Metawidget has JSR-303 support.

Because Metawidget wires up other frameworks, this means that Metawidget effectively adds JSR-303 support to Android, GWT, JSF (not only RichFaces), JSP, Spring MVC, Struts, Swing and SWT.

In my opinion (and I'm biased, I know) the UI frameworks should *not* be the ones directly inspecting annotations and altering their components to suit. I think that is beyond their scope. For example:

  • What if your JSR-303 annotated POJO is written in Groovy? Scala? Etc etc. Should Swing et al. really start worrying about that?
  • What if I want to use some extended features of Hibernate Validator 4? Is that up to, say, Android to support directly?
  • Do we really want PrimeFaces, RichFaces and Tomahawk each maintaining their own separate implementations of JSR-303 inspection? Worrying about whether you annotate your getters or your fields?
  • There are many other sources of UI metadata. Constraints may be stored in a database, for example, or a rule engine. Or maybe the language supports read-only properties (such as a getter without a setter). Should, say, SWT be expected to figure that out?

I would much rather some middleware (ie. Metawidget, OpenXava etc) takes the job of wiring UIs to domain objects, just as ORMs take the job of wiring domain objects to databases. We could think of this middleware as an Object User Interface Mapper (OIM).

Regards,

Richard.

Posted by Richard Kennard on March 09, 2011 at 08:42 PM MST #

OpenXava also supports JSR-303.

Posted by Javier Paniza on March 10, 2011 at 02:37 AM MST #

Perhaps an honorable mentioning of the framework 'Loom' that (by reading the comments) appear to have given Bernard some 'inspiration' :-)

http://icoloma.blogspot.com/2007/12/validate-web-forms-using-jpa.html

Client side JPA validation, last release nov 2010 but does not appear to support JSR-330 yet. Have not tried the last one though.

Jens

Posted by Jens on May 09, 2011 at 11:02 AM MDT #

Post a Comment:
  • HTML Syntax: Allowed