1 Reply Latest reply on Jul 7, 2010 11:08 AM by Hai-Yun Du

    facesMessages.addToControlFromResourceBundle not showing up in s:message

    Hai-Yun Du Newbie
      I am trying to validate a password field:

      <s:decorate id="password" template="/layout/edit.xhtml">
           <ui:define name="label">#{messages['person.password']}</ui:define>
           <h:inputSecret id="passwordValue" value="#{passwordBean.newPassword}"
                valueChangeListener="#{passwordBean.validateNewPassword}">
                <a4j:support event="onblur" reRender="password, passwordValue"/>
           </h:inputSecret>
      </s:decorate>

      ---------------------------------------------------------
      The edit.xhtml template:

      <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>

      ---------------------------------------------------------
      The passwordBean:

      @Name("passwordBean")
      @Scope(ScopeType.CONVERSATION)
      public class PasswordBean implements Serializable {

           @In private FacesMessages facesMessages;

           public void validateNewPassword(ValueChangeEvent e) {
                String newPass = (String) e.getNewValue();
                String compId = e.getComponent().getId();

                if (weakPassword(newPass)) {
                     facesMessages.addToControlFromResourceBundle(compId, "message.password");
                     return;
                }
           }
      }

      The password field error shows up upon validation, but the error message does not get displayed.