@Constraint(validatedBy=RequiredValidator.class) @Retention(value=RUNTIME) @Target(value={FIELD,METHOD}) public @interface Required
By default this is true for key properties hidden or without default value
calculator on create and false in all other cases. On saving OpenXava
verifies if the required properties are present. If this is not the
case, then saving is not done and a validation error list is returned.
The logic to determine if a property is present or not can be configured
by creating a file called validators.xml in your
project. You can see the syntax in OpenXava/xava/validators.xml.
Example:
@Required private int zipCode;In the case of reference you can use the JPA syntax as alternative:
@ManyToOne(optional=false) private State state;That is, for OpenXava
@ManyToOne(optional=false)
is synonymous of
@Required
.
Required
is also implemented as a Hibernate validation,
therefore it's executed when you save using JPA or Hibernate API.public abstract java.lang.String message
You can specify an id of the messages i18n file using braces:
message="{car_color_required}"Or directly the message:
message="You have to specify the car color"