I have created a Custom Validator, I have referenced it in a <h:inputText>
, the Validator is executed, no exception is raised, but the execution flow does not arrive in the Managed Bean.
Where should I be wrong?
<h:inputText id="cpf" size="18" maxlength="14" rendered="true" value="#{managedBean.usuario.CPF}">
<c:validator validatorId="cpfValidator" />
</h:inputText>
package br.web.jsf.validators;
import javax.faces.application.FacesMessage;
import javax.faces.component.UIComponent;
import javax.faces.context.FacesContext;
import javax.faces.validator.FacesValidator;
import javax.faces.validator.Validator;
import javax.faces.validator.ValidatorException;
import br.util.BibliotecaMetodos;
@FacesValidator("cpfValidator")
public class CPFValidator implements Validator {
@Override
public void validate(FacesContext pFacesContext, UIComponent pUiComponent, Object pObject) throws ValidatorException {
String cpf = (String) pObject;
if ( !BibliotecaMetodos.isCPFvalido(cpf) ) {
FacesMessage mensagem = new FacesMessage("O CPF é Nulo ou Inválido.");
mensagem.setSeverity(FacesMessage.SEVERITY_ERROR);
throw new ValidatorException(mensagem);
}
}
}