org.openxava.annotations
Annotation Type Required


@ValidatorClass(value=RequiredValidator.class)
@Retention(value=RUNTIME)
@Target(value={FIELD,METHOD})
public @interface Required

Indicates if this property or reference is 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.

Author:
Javier Paniza

Optional Element Summary
 java.lang.String message
          The message to be shown if the element is not present.
 

message

public abstract java.lang.String message
The message to be shown if the element is not present.

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"
 

Default:
"{required}"