Annotation Interface OnValidate
This annotation does not change when an object will be enqueued for validation. It only affects the behavior once validation of an instance is actually performed.
An optional list of validation groups()
may be specified; if so, the annotated method will only be invoked when
one or more of specified validation groups (or a superclass thereof) is being validated. In particular, if groups()
is non-empty and does not contain a class that extends Default
, then the method will
not be invoked by automatic validation.
The annotated method must be an instance method (i.e., not static), return void, and take zero parameters.
If validation fails, the method should throw a ValidationException
.
"Fixup" Validations
Annotated methods are not restricted from performing additional mutating operations in the transaction. Therefore, in some cases, it may be possible for an annotated method to actually fix a validation problem, by modifying a field or even deleting the object.
However, by default Permazen invokes @OnValidate
methods after the other validation checks
(i.e., JSR 303 and uniqueness constraints). This makes it easier to write @OnValidate
methods
because one can assume those checks have already passed, but it also means it is too late fix any violations
of those checks.
To have an @OnValidate
method inovked prior to the other validation checks instead of
after them, set early()
= true
. When doing this, be careful not to trigger infinite loops, as
@OnChange
notifications and @OnDelete
notifications will still occur.
Meta-Annotations
This annotation may be configured indirectly as a Spring
meta-annotation
when spring-core
is on the classpath.
-
Optional Element Summary
-
Element Details
-
groups
Class<?>[] groupsSpecify the validation group(s) for which the annotated method should be invoked.- Returns:
- validation group(s) to use for validation; if empty,
Default
is assumed
- Default:
- {}
-
early
boolean earlySpecify when to invoke the annotated method relative to JSR 303 and uniqueness constraint validation.If true, the annotated method will be invoked prior to JSR 303 and uniqueness constraint validation; if false, afterward.
- Returns:
- true to invoke the annotated method prior other validation checks
- Default:
- false
-