You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@myfaces.apache.org by "Lukas Lieb (Jira)" <de...@myfaces.apache.org> on 2026/07/07 09:21:00 UTC
[jira] [Commented] (MYFACES-4755) Only one BeanValidation on value as ParametrizableFacesMessage does not overwrite equals/hashCode
[ https://issues.apache.org/jira/browse/MYFACES-4755?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=18094252#comment-18094252 ]
Lukas Lieb commented on MYFACES-4755:
-------------------------------------
Hi [~tandraschko]
No pressure, but do you have any idea when 4.1.4 will be released?
> 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
> Priority: Major
> Fix For: 5.0.0, 4.1.4
>
>
> 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:
> {code: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 {};
> } {code}
> 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)