Annotation Type GwtValidation


@Documented @Target(TYPE) @Retention(SOURCE) public @interface GwtValidation
Annotates a javax.validation.Validator explicitly listing the classes that can be validated in GWT.

Define the Validator you want, explicitly listing the classes and groups you want to validate.

 @GwtValidation(value = {MyBean.class, MyOther.class}, 
groups = {Default.class, OtherGroup.class}) public interface MyValidator extends javax.validation.Validator { }

Create and use the validator.

 MyValidator validator = new MyValidatorImpl();
 MyBean bean = new MyBean();
 ...
 Set<ConstraintViolation<MyBean>> violations = validator.validate(bean);
 

You must list all validation groups you are using (as well as groups making up a group sequence)– unless you are only using the Default group, in which case you may omit the "groups" field of the GwtValidation annotation.

NOTE: Validation is done using only the Constraints found on the Classes listed in the annotation. If you have

 class MyBean {
   @Null
   String getName() {
     return name;
   }
 }


 class MySubBean extends MyBean {
   @Size(min = 5)
   String getName() {
     return super.getName();
   }
 }
 

And then create your ValidatorFactory using

 @GwtValidation(MyBean.class, MyOther.class)}
 

but call validator with the subclass like

 MySubBean bean = new MySubBean();
 Set<ConstraintViolation<MyBean>> violations = validator.validate(bean);
 

The Size constraint will not be validated.

Instead make sure you list the all BeanTypes that will be directly validated in the GwtValidation annotation.

  • Required Element Summary

    Required Elements
    Modifier and Type
    Required Element
    Description
    Class<?>[]
    The list of Classes which can be validated by the annotated Validator.
  • Optional Element Summary

    Optional Elements
    Modifier and Type
    Optional Element
    Description
    boolean
    force using getter for accessing field values.
    boolean
    generate reflection getter for class based validation.
    boolean
    generate validator factory interface to autoinclude valdator factory.
    Class<?>[]
    The list of Groups which can be processed by the annotated Validator.
    The list of languages to generate messages for.
    Class<?>[]
    The list of Classes which can be used a reflection getter, if empty all constrained beans are taken (autodetection).
  • Element Details

    • value

      Class<?>[] value
      The list of Classes which can be validated by the annotated Validator.
      Returns:
      array of classes
    • groups

      Class<?>[] groups
      The list of Groups which can be processed by the annotated Validator. The default value is Default. An empty array is illegal.
      Returns:
      array of classes
      Default:
      {javax.validation.groups.Default.class}
    • reflect

      Class<?>[] reflect
      The list of Classes which can be used a reflection getter, if empty all constrained beans are taken (autodetection). If generateReflectionGetter is set to false, no reflection getter is generated, even for classes of this list!
      Returns:
      array of classes
      Default:
      {}
    • forceUsingGetter

      boolean forceUsingGetter
      force using getter for accessing field values.
      Returns:
      boolean, true when only using getter
      Default:
      false
    • generateReflectionGetter

      boolean generateReflectionGetter
      generate reflection getter for class based validation.
      Returns:
      boolean, true when generating reflection getter
      Default:
      true
    • generateValidatorFactoryInterface

      boolean generateValidatorFactoryInterface
      generate validator factory interface to autoinclude valdator factory.
      Returns:
      boolean, true when generating interface
      Default:
      true
    • languages

      String[] languages
      The list of languages to generate messages for.
      Returns:
      array of strings
      Default:
      {"de", "fr", "en"}