Package org.openxava.annotations
Annotation Interface PropertyValidator
@Repeatable(PropertyValidators.class)
@Retention(RUNTIME)
@Target({FIELD,METHOD})
@Constraint(validatedBy=PropertyValidatorValidator.class)
public @interface PropertyValidator
The validator execute validation logic on the value assigned to the property
just before storing.
Applies to properties.
Example:
@PropertyValidator(UnitPriceValidator.class) private BigDecimal unitPrice;
PropertyValidator is also implemented as a Hibernate validation,
therefore it's executed when you save using JPA or Hibernate API, with the
exception of onlyOnCreate=true, in this last case the validation is only applied when
you save with OpenXava (using MapFacade or standard
OX actions).- Author:
- Javier Paniza
-
Required Element Summary
Required Elements -
Optional Element Summary
Optional ElementsModifier and TypeOptional ElementDescriptionClass<?>[]The message to be shown if validation fails.booleanIf true the validator is executed only when creating a new object, not when an existing object is modified.Class<? extends javax.validation.Payload>[]To set values to the validator properties before executing it.
-
Element Details
-
value
Class valueClass with the validation logic.Must implements
IPropertyValidator.
-
-
-
properties
PropertyValue[] propertiesTo set values to the validator properties before executing it.- Default:
- {}
-
onlyOnCreate
boolean onlyOnCreateIf true the validator is executed only when creating a new object, not when an existing object is modified.- Default:
- false
-
message
String messageThe message to be shown if validation fails.The validator class have to implement
IWithMessageto receive this message.
If not specified the message is not injected in the validator, in this case the validator should produce an appropriate default message.
You can specify an id of the messages i18n file using braces:message="{color_not_available}"Or directly the message:message="That color is not available. This car can be only red or yellow"
- Default:
- ""
-
groups
Class<?>[] groups- Default:
- {}
-
payload
Class<? extends javax.validation.Payload>[] payload- Default:
- {}
-