1.1.2. Developing your own validator

The user-configurable validator is implemented by the org.exoplatform.webui.form.validator.UserConfigurableValidator class.

To validate a field using a user-configurable validator, add the validator to the field like the example below:

addValidator(UserConfigurableValidator.class, validatorName);

where validatorName is a String that must match a validator name configured in configuration.properties.

You can see more codes of adding a validator to a field via UIAccountProfiles.java.

The validator instance can then be configured by adding the relevant information in configuration.properties, for example:

# validators
gatein.validators.{validatorName}.format.message=This value must start with ''u'' and be followed by 4 to 9 digits


The regular expressions used for validation are Java Regular Expressions.

Alternatively, a resource key can also be passed to the addValidator method to specify which localized message should be used in case a validation fails, for example:

addValidator(UserConfigurableValidator.class, validatorName, localizationKey);

In which, localizationKey is defined in a resource bundle.

Copyright ©. All rights reserved. eXo Platform SAS
blog comments powered byDisqus