myfaces-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Matthias Weßendorf (JIRA) <>
Subject [jira] Updated: (MYFACES-1734) In a custom validator method, the Message in the thrown ValidatorException is not used
Date Thu, 27 Sep 2007 15:10:51 GMT


Matthias Weßendorf updated MYFACES-1734:

       Resolution: Fixed
    Fix Version/s: 1.2.1-SNAPSHOT
           Status: Resolved  (was: Patch Available)

thx for the patch, Thomas Fischer !

> In a custom validator method, the Message in the thrown ValidatorException is not used
> --------------------------------------------------------------------------------------
>                 Key: MYFACES-1734
>                 URL:
>             Project: MyFaces Core
>          Issue Type: Bug
>          Components: General
>    Affects Versions:  1.2.0
>            Reporter: Thomas Fischer
>            Assignee: Matthias Weßendorf
>             Fix For: 1.2.1-SNAPSHOT
>         Attachments: myfaces-1734-patch.txt
> Situation: A custom validator is defined in a jsp, e.g.
> <h:inputSecret id="loginPass" value="#{loginController.password}" required="true"
label="Password" validator="#{loginController.validate}"/>
> The error message from validation is displayed on the same page by <h:messages/>.
For testing reasons, the validate method always throws an error:
> public void validate(FacesContext context, UIComponent component, Object value)
> {
>   FacesMessage message
>       = new FacesMessage(FacesMessage.SEVERITY_ERROR, "message summary", "message detail");
>   throw new ValidatorException(message);
> }
> Expected behaviour:  After a form submit, the error message "message summary" should
be displayed by the <h:messages/> tag.
> Observed behaviour: An empty message is displayed by the <h:messages/> tag.
> Reason: in javax.faces.validator.MethodExpressionValidator#validate(FacesContext, UIComponent,
Object), all ELExceptions are caught, and a ValidationException with a empty message is thrown.
This empty message is then displayed by <h:messages/>
> Resolution: The original ValidatorException is still contained as cause of the ElException.
This is required by the contract of MethodExpression.invoke:
> <quote>
> ... throws ELException - if an exception was thrown while performing property or variable
resolution. The thrown exception must be included as the cause property of this exception,
if available...
> </quote>
> So one should retrieve the cause of the ELException and check whether it is a ValidatorException.
If yes, the cause(containing the original message) should be rethrown. If no, the error is
not a validation error but something else, then the ELException should be rethrown (Reason
for this: In the current implementation, if another error (no validation error) occurs, e.g.
the user mistypes the method name in the jsp, no exception stack trace is displayd but only
an empty faces message is added. It is very difficult to find the error. Re-throwing the EL
exception removes this problem.)

This message is automatically generated by JIRA.
You can reply to this email to add a comment to the issue online.

View raw message