Tutorial :Declarative validation of forms in Java/Swing



Question:

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?


Solution:1

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.


Solution:2

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/


Solution:3

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.


Note:If u also have question or solution just comment us below or mail us on toontricks1994@gmail.com
Previous
Next Post »