Skip to content
doe300 edited this page Jan 30, 2015 · 1 revision

Validations

JActiveRecord supports validation of attributes in record-types.

There are several ways to implement validation:

Setter-Validation

These validations are only run on a specifiy setter-method.

Proxy-based Records

The AttributeSetter annotation lets you specify a validatorClass and a validatorMethod. This method must accept a single parameter of type Object (the value to validate). It checks the parameter for validity and throws an ValidationFailed if the object is invalid.

POJO-based Records

POJO-based Records can easily call own validations by executing them in their setter-methods.

Validation on Save

The ValidatedRecord interface provides methods to validate the attributes of a record. The validate() method is automatically called on saving a record via its RecordBase.

Overriding validation-methods

ValidatedRecords can override isValid() and validate() in order to provide custom checks for validation. This works for proxy-based and POJO-based Records.

Generating validation-methods

A proxy-based record-type (extending ValidatedRecord) can be annotated with Validate, or the @Repeatable version validates. This annotation specifies a single validation for one attribute. Besides some predefined validation, a custom validation-method can be set (much like AttributeSetter).

When the RecordBase for this type is built with ValidationHandler, the isValid() and validate() methods are automatically generated according to the rules in the annotations.

NOTE: Currently, if any of the validation-methods is overridden, the ValidationHandler will not handle it, but the overriding method will be called.

Clone this wiki locally