Download

Get Loom

Validation and Conversion

Checking user input

User interfaces like HTML forms need to check user input for validation according to the business rules. Any errors should not be handled as exceptions but instead collected and displayed as a list, forwarding the request to the source form that triggered the event.

There are two types of errors:

Conversion

HttpServletRequest have all the request parameters as plain text which must be converted prior to assigning them as java objects. This conversion is performed by Converter classes that transform text to native java objects according to the request locale.

Converter instances are stored in a ConverterFactory that returns the appropriate Converter for each class property, which can be overriden using the @ConverterMetadata annotation. Any errors during conversion of a parameter will skip the population and further validation of the corresponding java property.

Converters contribute to generate attributes of the rendered HTML field, such as CSS classes and maxlength attributes, for example.

Validation

Validations are performed on the java property and may differ depending on the property class: integer, dates, strings, all have their corresponding validation annotation that get processed and translated into Validator instances at startup time. Validations are locale-independent, while conversion is not.

For a list of annotations included with Loom, see the validations package.