-
Notifications
You must be signed in to change notification settings - Fork 0
Validations
JActiveRecord supports validation of attributes in record-types.
There are several ways to implement validation:
These validations are only run on a specifiy setter-method.
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 can easily call own validations by executing them in their setter-methods.
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.
ValidatedRecords can override isValid() and validate() in order to provide custom checks for validation. This works for proxy-based and POJO-based Records.
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.