Lukas Lieb created MYFACES-4755:
-----------------------------------

             Summary: Only one BeanValidation on value as 
ParametrizableFacesMessage does not overwrite equals/hashCode
                 Key: MYFACES-4755
                 URL: https://issues.apache.org/jira/browse/MYFACES-4755
             Project: MyFaces Core
          Issue Type: Bug
    Affects Versions: 4.1.3
            Reporter: Lukas Lieb


If I have multiple BeanValidation annotations on one field, that report a 
validation message, only one will be shown in the UI. E.g. consider the 
following class:

```java

@Size(min = 2)
@UpperCase
@Target( \{ METHOD, FIELD, ANNOTATION_TYPE })
@Retention(RUNTIME)
@Constraint(validatedBy = ValidLicensePlateValidator.class)
@Documented
public @interface ValidLicensePlate {
    String message() default "Field does not contain a valid license plate 
(e.g. SZ45232)";
    Class<?>[] groups() default {};
    public abstract Class<? extends Payload>[] payload() default {};
}

```

With a value of e.g. 's' it should report at least 3 messages:
 * should be uppercase
 * min size
 * does not match regex 2 chars then numbers

 

The `jakarta.faces.validator.BeanValidator#validate` method does collect all 
constraintViolations and convert them into a FacesMessages Set. 
https://github.com/apache/myfaces/blob/4.1.x/api/src/main/java/jakarta/faces/validator/BeanValidator.java#L224-L232

However, since the `jakarta.faces.application.FacesMessage` has implemented 
equals and hashCode methods (since v4.1), only the first message is added to 
the Set.

Why? Because the `MessageUtils.getErrorMessage(context, MESSAGE_ID, args)` does 
create objects of type 
`org.apache.myfaces.core.api.shared.ParametrizableFacesMessage` so the summary 
of the messages are always something like `\{0}: \{1}`. So the hashCode for all 
messages is the same even if the args are not.

So IMO the ParametrizableFacesMessage should also implement the equals and 
hashCode methods, so all the messages are added to the Set again.

 

Probably this is also a problem on v5.



--
This message was sent by Atlassian Jira
(v8.20.10#820010)

Reply via email to