3 Replies Latest reply on Feb 25, 2011 10:09 AM by Ilya Shaikovsky

    RF4 M6 - Object Validation only works with h:commandButton, not a4j:commandButton

    Flávio Henrique Newbie

      When I use a4j:commandButton, I can´t get Object Validation work, but, if I change it to h:commandButton, works fine. What I am doing wrong?

       

      The Bean

       

      package teste;

       

      import java.io.Serializable;

      import javax.faces.application.FacesMessage;

      import javax.faces.bean.ManagedBean;

      import javax.faces.bean.ViewScoped;

      import javax.faces.context.FacesContext;

      import javax.validation.constraints.AssertTrue;

      import org.hibernate.validator.constraints.Length;

       

      @ManagedBean

      @ViewScoped

      public class ValidatorMB implements Serializable {

       

                private static final long serialVersionUID = 1L;

       

                @Length(min = 8, max = 12)

                private String senha;

       

                @Length(min = 8, max = 12)

                private String confirmar;

       

                @AssertTrue(message = "Senha não confirma!")

                public boolean isPasswordsEquals() {

                          return senha.equals(confirmar);

                }

       

                public String getSenha() {

                          return senha;

                }

       

                public void setSenha(String senha) {

                          this.senha = senha;

                }

       

                public String getConfirmar() {

                          return confirmar;

                }

       

                public void setConfirmar(String confirmar) {

                          this.confirmar = confirmar;

                }

       

                public String gravar() {

                          System.out.println("gravar()");

                          FacesContext.getCurrentInstance().addMessage(

                                              null,

                                              new FacesMessage(FacesMessage.SEVERITY_INFO,

                                                                  "Succesfully changed!", "Succesfully changed!"));

                          return null;

                }

      }

       

      The pag

       

      <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

      <html xmlns="http://www.w3.org/1999/xhtml"

                xmlns:h="http://java.sun.com/jsf/html"

                xmlns:f="http://java.sun.com/jsf/core"

                xmlns:ui="http://java.sun.com/jsf/facelets"

                xmlns:a4j="http://richfaces.org/a4j"

                xmlns:rich="http://richfaces.org/rich">

      <h:head>

      </h:head>

      <h:body>

                <h:form>

                <rich:graphValidator value="#{validatorMB}">

                          <rich:panel>

                                    <f:facet name="header">

                                              <h:panelGroup>

                                                        <h:outputText value="User information" />

                                              </h:panelGroup>

                                    </f:facet>

                                    <rich:messages/>

                                    <h:panelGrid columns="3">

                                              <h:outputText value="Name:" />

                                              <h:inputText id="senha" label="Senha" value="#{validatorMB.senha}">

                                                        <rich:validator />

                                              </h:inputText>

                                              <rich:message for="senha" />

                                              <h:outputText value="Confirmar" />

                                              <h:inputText id="confirmar" label="Confirmar" value="#{validatorMB.confirmar}">

                                                        <rich:validator />

                                              </h:inputText>

                                              <rich:message for="confirmar" />

                                    </h:panelGrid>

                                    <a4j:commandButton value="Ok" action="#{validatorMB.gravar}"/>

                          </rich:panel>

                          </rich:graphValidator>

                </h:form>

      </h:body>

      </html>