javaserverfaces
  1. javaserverfaces
  2. JAVASERVERFACES-2515

Bean Validation message override for a specific property overrides all other properties with same annotation

    Details

    • Type: Bug Bug
    • Status: Closed
    • Priority: Major Major
    • Resolution: Cannot Reproduce
    • Affects Version/s: 2.1.13
    • Fix Version/s: 2.2.3
    • Component/s: None
    • Labels:
      None
    • Environment:

      using jsf 2.1.13 with hibernate-validator 4.3.0 on Tomcat 7.0.29
      Windows 7
      eclipse Indogo SR2 + JBoss Tools 3.3 final

      Description

      if i define a custom message for the property firstname :

      @Size(min = 2, groups = Personal.class)
      @NotNull(message = "very important, should not be null !", groups = Personal.class)
      public String getFirstName()

      { return firstName; }

      If null, i will get the message : very important, should not be null !

      Now if another property use the same annotation @NotNull

      @Size(min = 2, groups = Personal.class)
      @NotNull(groups = Personal.class)
      public String getLastName()

      { return lastName; }

      If null i will also get the same message as above : very important, should not be null !

      The order in which the getters are written in the User.java bean changes the behaviour.

      If the method getFisrtname() is before getLastname() the behaviour is what i described above.

      If the method getFisrtname() is AFTER getLastname() the behaviour the message override is ignored.

      So it seems the the first message definition is used for all other appearance of the @NotNull annotation.
      I tried with other annotations (@NotBlank ..) with the same conclusion

        Activity

        Hide
        Manfred Riem added a comment -

        Can you please attach an example application (with sources) that demonstrates the problem?

        Show
        Manfred Riem added a comment - Can you please attach an example application (with sources) that demonstrates the problem?
        Hide
        gpeel added a comment -

        With JSF2

        -call the form.faces
        -don't fill in the inputtext
        -submit
        =>
        messages are :
        First name: my message override for FISRTNAME
        Last name: my message override for FISRTNAME <<<<<<<<< KO

        the fisrt message is OK
        the second is NOT.

        it should be :
        First name: my message override for FISRTNAME
        Last name: ne peut pas être vide

        if in en
        First name: my message override for FISRTNAME
        Last name: may not be empty

        If i test the validation without JSF2 :
        using /jsf2-bean-validation-303-bug/src/main/java/beanvalidation/StandAloneTest.java
        if User.fisrtName and User.lastName are empty, the sare different, because
        there is an override on firstName only:
        @Size(min = 2)
        @NotBlank(message = "my message override for FISRTNAME")
        public String getFirstName()

        { getLog().debug("in"); return firstName; }

        18:34:37,183 INFO (Version.java:27).<clinit>() - HV000001: Hibernate Validator 4.3.0.Final
        18:34:37,339 DEBUG (User.java:35).getLastName() - in
        18:34:37,354 DEBUG (User.java:28).getFirstName() - in
        18:34:37,354 DEBUG (User.java:28).getFirstName() - in
        18:34:37,354 DEBUG (User.java:35).getLastName() - in
        ConstraintViolationImpl

        {interpolatedMessage='my message override for FISRTNAME', propertyPath=firstName, rootBeanClass=class beanvalidation.User, messageTemplate='my message override for FISRTNAME'}

        ConstraintViolationImpl{interpolatedMessage='ne peut pas être vide', propertyPath=lastName, rootBeanClass=class beanvalidation.User, messageTemplate='

        {org.hibernate.validator.constraints.NotBlank.message}

        '}
        the end

        We see that the messages is different.

        "my message override for FISRTNAME" appears for a violation on firstName, which is correct.

        Show
        gpeel added a comment - With JSF2 -call the form.faces -don't fill in the inputtext -submit => messages are : First name: my message override for FISRTNAME Last name: my message override for FISRTNAME <<<<<<<<< KO the fisrt message is OK the second is NOT. it should be : First name: my message override for FISRTNAME Last name: ne peut pas être vide if in en First name: my message override for FISRTNAME Last name: may not be empty If i test the validation without JSF2 : using /jsf2-bean-validation-303-bug/src/main/java/beanvalidation/StandAloneTest.java if User.fisrtName and User.lastName are empty, the sare different, because there is an override on firstName only: @Size(min = 2) @NotBlank(message = "my message override for FISRTNAME") public String getFirstName() { getLog().debug("in"); return firstName; } 18:34:37,183 INFO (Version.java:27).<clinit>() - HV000001: Hibernate Validator 4.3.0.Final 18:34:37,339 DEBUG (User.java:35).getLastName() - in 18:34:37,354 DEBUG (User.java:28).getFirstName() - in 18:34:37,354 DEBUG (User.java:28).getFirstName() - in 18:34:37,354 DEBUG (User.java:35).getLastName() - in ConstraintViolationImpl {interpolatedMessage='my message override for FISRTNAME', propertyPath=firstName, rootBeanClass=class beanvalidation.User, messageTemplate='my message override for FISRTNAME'} ConstraintViolationImpl{interpolatedMessage='ne peut pas être vide', propertyPath=lastName, rootBeanClass=class beanvalidation.User, messageTemplate=' {org.hibernate.validator.constraints.NotBlank.message} '} the end We see that the messages is different. "my message override for FISRTNAME" appears for a violation on firstName, which is correct.
        Hide
        Manfred Riem added a comment -

        I have verified that your example works properly on 2.2.3. Note I did have to make one adjustment (your page was referring to the 'firstName' property twice in the home.xhtml page), and it was the reason why you were seeing the same message twice.

        Show
        Manfred Riem added a comment - I have verified that your example works properly on 2.2.3. Note I did have to make one adjustment (your page was referring to the 'firstName' property twice in the home.xhtml page), and it was the reason why you were seeing the same message twice.

          People

          • Assignee:
            Manfred Riem
            Reporter:
            gpeel
          • Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

            Dates

            • Created:
              Updated:
              Resolved: