Validation Framework Consolidation
Looks like Jason Carreira has stepped up to the plate to try and consolidate the validation frameworks we have in Java. I'm sure it was a joint effort among many, but Jason's name is the only one I see on the JSR. I applaud this effort - it's definitely needed.
I've used Commons Validator, the XWork Validation Framework as well as Hibernate's Validator. While Commons and XWork work, the ability to annotate a class and validate it anywhere/anyhow is pretty cool. I reviewed an article a couple months ago that hooked Hibernate Validator into Spring MVC and Prototype for client-side validation. There's a lot of good stuff in this space - let's hope this JSR creates something even better. More than anything, let's hope it doesn't brush off client-side validation like JSF did.
In an ideal world, the RIFE, Spring MVC, Stripes, Struts, Tapestry and Wicket developers will all participate and allow JSR-303's result to be used as their framework's validation engine. I think it's a given that this will be usable with JSF.
Posted by Jason Carreira on July 11, 2006 at 08:44 PM MDT #
Posted by Stephen Duncan Jr on July 11, 2006 at 08:55 PM MDT #
Posted by Lars Fischer on July 11, 2006 at 09:39 PM MDT #
Posted by Geert Bevin on July 11, 2006 at 10:39 PM MDT #
Posted by Jacob Hookom on July 12, 2006 at 01:42 AM MDT #
Posted by Sanjiv Jivan on July 12, 2006 at 03:49 AM MDT #
Posted by Jacob Hookom on July 12, 2006 at 04:51 AM MDT #
Posted by Sanjiv Jivan on July 12, 2006 at 10:35 AM MDT #
As a side note, I don't really see the need to make this a JSR. Jason, what's the rationale behind that?
Commons Validator was an attempt to make a general validation framework. We considered using that for Wicket, but decided against it because it was too much bloat for our needs. But hey, maybe I'm just being too pessimistic. Jason, if you're really interested in making this a cross-framework thing, drop us a line.
Posted by Eelco Hillenius on July 12, 2006 at 01:18 PM MDT #
There are a lot of validation frameworks out there. Lots of libraries and frameworks touch on validation, and they seemingly all build their own validation. Most of the validation frameworks end up being pretty specific to the environment they're built for, whether it's a Swing UI or a web app, so it's hard to get re-use across projects, or even within one project from the UI through the back-end processing. And that's just the opensource libraries and people's applications... What about the other JSRs? JSF, JPA, Bean Binding, etc... All of them touch on validation. All of them either do or will end up implementing their own validation interfaces. They can't be written to commons-validation, it's not a spec. So then you're stuck with your web framework's validation framework API, your persistence tier's validation framework API, and probably your own applications validation API. How do you get reuse of validations across all tiers in the app?
I personally am able to use my validations front to back in both the web UI and batch processing, and we make use of that to have consistent validations throughout our app, but I'm pretty sure that's the exception, not the rule.
That's why we need a JSR for this. It should also make a nice platform for tool support, whether it's validation-aware Swing UI widgets or a JavaScript client-side validation library.
To Sanjiv's point, someone may convince me and the EG that a JavaScript library is in scope, but I doubt it. Read the JSR proposal. It's an extension to the JavaBeans contract. It's NOT driven by web app validation, but general JavaBean validation. There's been a lot of work going on defining meta-data about beans, and this is just another set of meta-data.
Plus, you can't say in one post that open source moves faster than specs then in the next post complain that we don't want to specify MORE... Especially something as quickly evolving and nebulous as JavaScript... I've never seen a JS validation library that gets everything right, and I'd hate to push out a "JSR-blessed" JS validation library that's not good enough for most people... Plus, what does a JS validation library mean for Swing apps?
Posted by Jason Carreira on July 12, 2006 at 02:13 PM MDT #
Posted by Sanjiv Jivan on July 12, 2006 at 03:52 PM MDT #
Posted by Jacob Hookom on July 12, 2006 at 04:16 PM MDT #
Not only for validating plain user-defined data, but certainly also in this age of dependency injection etc.
When validation rules can be defined inside/close-to the actual class, a class designer/developer could enforce the right checks to make sure an instance is ready for use, irrespective of type N IOC or whatever way of externalized instance initialization is used.
Externally defined validation rules (like the current typical XML-based stuff) could define application-specific extensions.
cheers
Erwin
Posted by erwin on July 13, 2006 at 08:40 AM MDT #
Seems to me that there are different levels of meta data in a validation framework. Theres *global* type stuff such as configuring validation handlers for specific types - (e.g "this is my date handling routine") and then theres application specific meta data where you define the rules for that application (e.g. "validate that the credit card expiry date on my customer bean is a valid future date").
In the same way that the java (server side) needs to know how to get hold of the *global* routines and invoke them, providing the location of an equivalent script validation routine and something that knows how to render/generate the appropriate script to invoke it would be useful meta data for validation frameworks.
It also isn't necessarily a web/server side specific feature with the Scripting support coming in Mustang. I would say it would be deficient if the EG didn't at least give some thought to Script validation.
A while ago I developed this type of feature for Commons Validator - it was a first pass hack and hasn't been implemented, but worked pretty well:
http://www.niallp.pwp.blueyonder.co.uk/validatorjs.html
http://issues.apache.org/jira/browse/VALIDATOR-106
Posted by Niall on July 13, 2006 at 11:49 AM MDT #
So, a mostly non-Ajax application has two options:
Another option is to use GWT, it can translate Java into Javascript. So if this JSR produces Java 1.4 compliant code, then there is a possibility to use GWT Java-to-Javascript compiler to produce Javacript validator code right from Java code instead of building Javascript validator routines manually.
2) Pulling metadata out of entity EJBs (anyone uses them?) or from database is important. But this relates not only to validation, but to automatic composition of backing bean / action form out of database schema. In would be nice if value objects/backing beans were created automatically using database schema, having proper type, size and constraints (validators, here you are).
Therefore I don't think that tackling metadata is up to this JSR. There should be another JSR for that. I think there is one proposed by Seam team.
Posted by Michael Jouravlev on July 14, 2006 at 05:31 PM MDT #
Posted by Sudhir Nimavat on January 09, 2007 at 07:20 AM MST #
Posted by Anthony Whitford on January 28, 2007 at 04:11 PM MST #
Posted by bhaskary on June 19, 2007 at 01:50 PM MDT #