views:

872

answers:

3

I use Java for client-side development with Swing. I love Swing; I believe it is one of the better GUI frameworks there. What I miss, however, is the support for declarative validation. Like this snippet from XForms.

Do you know any library which allows validating data entry in forms in a declarative way, not by writing ugly validation document listeners for every component there?

A: 

You only have to write ugly validating models once. You can them use them in a "declarative way". Actual useful Swing libraries is a more difficult question.

Tom Hawtin - tackline
I know. But I am facing a project with LOTS of forms (and validation rules), so I would prefer not to reinvent the wheel.
Alexander Temerev
What does the number of forms have to do with it?
Tom Hawtin - tackline
It is reinventing the wheel. Why do you need to write email address validator? This things should be already implemented.
umpirsky
+5  A: 

You could try one of the implementations of JSR 303 Bean Validation. I don't think it is finalized yet but there are a few implementations around like Hibernate Validator and Agimatec Validation. I haven't tried either but reading through some examples of how Bean Validation will be used makes it look promising. Here is an interview with the spec lead. What I like most about the proposal is that the validation rules can be reused in different layers and with different frameworks. You can choose between annotations and xml for doing the 'declaring'.

Lastly you might want to check out Swing Java Builders which provides a declarative way for defining GUIs and doing validation and data binding with Swing.

Patrick
I don't know if I'm getting IE bugs or what, but the first link keeps running into the second link (so everything between "JSR 303" and "around like" is part of the link). With Joel Coehoorn's edits, the first link wasn't a link at all--it looked like "http://jcp.org/en/jsr/detail?id=303>JSR 303"...
Michael Myers
Maybe together with something like <a href="https://beansbinding.dev.java.net/">Beans Binding</a> or <a href="https://binding.dev.java.net/">JGoodies Binding</a>
keuleJ
+1  A: 

You may look at my attempt to build a Swing GUI builder, that uses JSR303 validation with Hibernate Validator: http://code.google.com/p/swing-formbuilder/

eav