​XML configured validation

Hi friends!

I am working on a utility class for Vaadin, which can help you declare validators with XML files, so you will no need to create validator instances and set all the validator properties in your Java code.
I think this will separate the input-validation code and the real business logic code, and
make the app more maintainable.

The basic idea is simple:

  1. Define validators and their properties in XML file
  2. Load validator definition info from XML file
  3. Create validator instance and setup all the properties, and then bind validator to the data input fields.

For example, we have a user register form, and input fields for [username]
and [password]
.
The validator configuration file will be:

<?xml version="1.0" encoding="UTF-8"?>
<validatorConfig>
    <!-- Field: "name" -->
    <field name="name">
        <!-- not null -->
        <validator type="Null">
            <msg text="${validate.null.input}">
                <param>${label.user.name}</param>
            </msg>
        </validator>

        <!-- lenght: 2-32 characters -->
        <validator type="StrLength">
            <msg text="${validate.lengthRange}">
                <param>${label.user.name}</param>
                <param>${min}</param>
                <param>${max}</param>
            </msg>
            <min>2</min>
            <max>32</max>
        </validator>
    </field>

    <!-- Field: "password" -->
    <field name="password">
        <!-- not null -->
        <validator type="Null">
            <msg text="${validate.null.input}">
                <param>${label.user.password}</param>
            </msg>
        </validator>

        <!-- lenght: 5-32 characters -->
        <validator type="StrLength">
            <msg text="${validate.lengthRange}">
                <param>${label.user.password}</param>
                <param>${min}</param>
                <param>${max}</param>
            </msg>
            <min>5</min>
            <max>32</max>
        </validator>
    </field>
</validatorConfig>

And the Java code will be:

[code]
// bind field to Java Bean property
this.fieldGroup.bind(this.nameField, UserDTO.PROP_NAME);
// bind field to Java Bean property
this.fieldGroup.bind(this.passwordField, UserDTO.PROP_PASSWORD);

// Load validator definition info from XML file
ValidatorConfigContainer validatorConfig = ValidatorConfigContainer.loadFrom(this);
// Create validator instance and setup all the properties, and then bind validator to the data input fields
validatorConfig.addValidators(this.fieldGroup);
[/code]this code will create validators for all the fields in the fieldGroup.

or you can create validators for fields one by one:

validatorConfig.addValidators(this.nameField, "name");
validatorConfig.addValidators(this.passwordField, "password");

I have finished this utility class, and used it in my app. It works fine.

How do you think about it?
If it is valuable for other programmers, I think maybe I can create an add-on, and release it to the Vaadin Directory

Any feedback is welcome!
Thanks very much!

Hi, is anyone interested in this?