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

      Hello,


      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}"
        valueChangeListener="#{passwordBean.validatePassword}">
        <a4j:support event="onblur" reRender="password, passwordValue"/>
       </h:inputSecret>
      </s:decorate>
      



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


      <ui:composition xmlns="http://www.w3.org/1999/xhtml"
                       xmlns:ui="http://java.sun.com/jsf/facelets"
                       xmlns:h="http://java.sun.com/jsf/html"
                       xmlns:f="http://java.sun.com/jsf/core"
                       xmlns:s="http://jboss.com/products/seam/taglib">
      
          <div class="prop">
      
              <s:label styleClass="name #{invalid?'errors':''}">
                  <ui:insert name="label"/>
                  <s:span styleClass="required" rendered="#{required}">*</s:span>
              </s:label>
      
              <span class="value #{invalid?'errors':''}">
                  <s:validateAll>
                      <ui:insert/>
                  </s:validateAll>
              </span>
      
              <span class="error">
                  <h:graphicImage value="/img/error.gif" rendered="#{invalid}" styleClass="errors"/>
                  <s:message styleClass="errors"/>
              </span>
      
          </div>
      
      </ui:composition>
      



      Here is the passwordBean that contains the validation method:


      @Name("passwordBean")
      @Scope(ScopeType.CONVERSATION)
      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");
         return;
        }
       }
      }
      



      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.