Uploaded image for project: 'Wicket'
  1. Wicket
  2. WICKET-6499

Support for Bean Validation 2.0

    XMLWordPrintableJSON

Details

    • Improvement
    • Status: Resolved
    • Major
    • Resolution: Fixed
    • 7.9.0, 8.0.0-M8
    • 8.0.0-M9
    • wicket-bean-validation
    • None

    Description

      Bean Validation 2.0 and the reference implementation Hibernate Validator 6.0 were recently released.

      I upgraded my application and discovered that fields annotated with @NotEmpty and @NotBlank are not automatically marked as required anymore.

      So I started to investigate.

      Bean Validation 1.x

      Wicket PropertyValidator marks form components as required if it encounters the @NotNull annotation on a field:

      boolean isRequired()
      	{
      		List<NotNull> constraints = findNotNullConstraints();
      		for (NotNull constraint : constraints)
      		{
      			...
      		}
      		return false;
      	}
      

      In Bean Validation 1.x, this lookup returns not only properties annotated with

      • @javax.validation.constraints.NotNull

      but also properties annotated with

      • @org.hibernate.validator.constraints.NotEmpty
      • @org.hibernate.validator.constraints.NotBlank

      because these annotations are implemented as composed constraints:

      @NotNull
      @Deprecated
      public @interface NotEmpty {}
      
      @NotNull
      @Deprecated
      public @interface NotBlank {}
      

      Bean Validation 2.x

      Both annotations are now deprecated and replaced with "official" versions:

      • javax.validation.constraints.NotEmpty
      • javax.validation.constraints.NotBlank

      The new annotations are not implemented as composed constraints, and thus do not contain the @NotNull annotation.

      I asked about the rationale and the recommended solution on the HV forum and got the following reply from the Hibernate Team:

      When promoting @NotEmpty and @NotBlank from HV to the Bean Validation spec we decided to define them as composed constraints (as their previous counterparts), but instead leave this as an implementation detail to BV providers. The reason being, that the implementation can be more efficient when using a single constraint validator instead of relying on constraint composition.

      So you'd indeed have to expand your scan to look for @NotNull, @NotEmpty and @NotBlank.

      I suggest that PropertyValidator should scan for these new annotations when Bean Validation 2.0 is on the classpath.

      Attachments

        Issue Links

          Activity

            People

              Unassigned Unassigned
              thomas.heigl Thomas Heigl
              Votes:
              0 Vote for this issue
              Watchers:
              7 Start watching this issue

              Dates

                Created:
                Updated:
                Resolved: