Hi all,

In an application using myfaces 1.2.0, a custom validation method is added
by the validator attribute.  E.g.

<h:inputSecret id="loginPass" value="#{loginController.password}" validator
="#{loginController.validate}"/>

For testing purposes, the validator method always fails:

public void validate(FacesContext context, UIComponent component, Object
value)
{
  FacesMessage message
      = new FacesMessage(FacesMessage.SEVERITY_ERROR, "message summary",
"message detail");
  throw new ValidatorException(message);
}

The following strange behaviour is observed:
1) the validate method is called twice. Debugging this, one sees that two
same validators have been added to the component. This is because the
setProperties() method of the Tag is called twice during creation of the
component, each one adding a validator instance.

2) The message text is not displayed by a <h:messages/> tag, instead two
empty messages are displayed. If one changes the validate method to

public void validate(FacesContext context, UIComponent component, Object
value)
{
  ((UIInput) component).setValidatorMessage("some Message");
  throw new ValidatorException(null);
}

the message text gets displayed, but twice(see 1)).

I'd reckon that the behaviour is a bug (actually, two bugs). Or can anyone
spot anything I have done wrong ?

If no errors on my side can be found, I'd offer to create a patch for this
to create the following behaviour:
- the validate method is called only once, and only one failure message is
displayed
- the FacesMessage in the ValidationException is displayed if the
validatorMessage attribute is not set

   regards,

     Thomas

Reply via email to