1 Reply Latest reply on Jul 24, 2006 7:05 PM by Gavin King

    FacesMessages looses component ID for validation?

    Andrew Apprentice

      Okay, I am observing some odd behavior. I have a backing bean with a custom validation method. In there I added a validation error message using the FacesMessages.add(String, FacesMessage) method. However, when I debug the faces context, the message is there, but the component ID is not. If I use the normal FacesContext to add the message it works.

      Works:

      public void validUniqueName(FacesContext context,
       UIComponent toValidate, Object value)
      {
       ...
       context.addMessage(toValidate.getClientId(context),
       FacesUtils.createErrorMessage("liverep_uniquename", name));


      Doesn't work:
      public void validUniqueName(FacesContext context,
       UIComponent toValidate, Object value)
      {
       ...
       facesMessages.add(toValidate.getClientId(context),
       FacesUtils.createErrorMessage("liverep_uniquename", name));


      When it works, my debugging code prints:
      16:14:05,231 DEBUG [DebugPhaseListener] Faces message found.
       Component: lreActionPane:name
       Severity : Error
       Summary : A template already exists with the name 'Test report'
       Detail : A template already exists with the name 'Test report'


      When I use facesMessages:
      16:14:05,231 DEBUG [DebugPhaseListener] Faces message found.
       Component: null
       Severity : Error
       Summary : A template already exists with the name 'Test report'
       Detail : A template already exists with the name 'Test report'


      What am I missing? Why is the client ID not included?

      Thanks,
      Andrew