0 Replies Latest reply on Jul 8, 2010 10:35 AM by Hai-Yun Du

    Cannot get in field error message to display

    Hai-Yun Du Newbie


      I am having a problem with getting an error message to display for an input field. I am calling a valueChangeListener method to validate the field, and if validation fails it adds a message for that input component.

      Here is the input field xhtml snippet:

      <s:decorate id="password" template="/layout/edit.xhtml">
       <ui:define name="label">Password</ui:define>
       <h:inputSecret id="passwordValue" value="#{passwordBean.password}"
        <a4j:support event="onblur" reRender="password, passwordValue"/>

      Here is the edit.xhtml template around the input field:

      <ui:composition xmlns="http://www.w3.org/1999/xhtml"
          <div class="prop">
              <s:label styleClass="name #{invalid?'errors':''}">
                  <ui:insert name="label"/>
                  <s:span styleClass="required" rendered="#{required}">*</s:span>
              <span class="value #{invalid?'errors':''}">
              <span class="error">
                  <h:graphicImage value="/img/error.gif" rendered="#{invalid}" styleClass="errors"/>
                  <s:message styleClass="errors"/>

      Here is the passwordBean that contains the validation method:

      public class PasswordBean implements Serializable {
       @In private FacesMessages facesMessages;
       private String password;
       public void validateNewPassword(ValueChangeEvent e) {
        String newPass = (String) e.getNewValue();
        String compId = e.getComponent().getId();
        if (weakPassword(newPass)) {
         facesMessages.addToControlFromResourceBundle(compId, "message.password");

      What actually happens when validation fails is that the error highlighting appears around the field but the error message does not, both of which I don't understand. First of all, how does Seam know that an error occurred when the valueChangeListener is called? Secondly, why does the error message not show up when it was added to facesMessages using the resource bundle and component id?

      Please shed some light on this if you can.