Geomajas Community Documentation

12.2.1.1. Validation

Most feature attributes should be validated before they can be saved to a file or database. Validation is a concern that stretches across many layers of a typical application: there is usually a need for client-side validation (making the application more user friendly) , server-side validation (to protect the server from invalid data) as well as database validation (to preserve data integrity). Preferably validation rules should be defined as much as possible in a single place to avoid conflicts and duplication.

Our attribute configuration supports several types of validation by defining a "validator" property inside the attribute:

<property name="validator">
    <bean class="org.geomajas.configuration.validation.ValidatorInfo">
        <property name="toolTip" value="Is this city a capital city or not? (Y or N)" />
        <property name="errorMessage" value="Invalid value: The value must be either Y or N." />
        <property name="constraints">
            <list>
                <bean class="org.geomajas.configuration.validation.NotNullConstraintInfo" />
                <bean class="org.geomajas.configuration.validation.PatternConstraintInfo">
                    <property name="regexp" value="[YN]$" />
                </bean>
            </list>
        </property>
    </bean>
</property>

Example 12.4. Attribute validator configuration


This property contains some general validator information and a set of constraints that should be applied to the attribute. The available constraint types have been based on the new JavaBeans standard: JSR-303.