Validar campo cpf com richfaces+Jquery

1 resposta
lulubr

Olá pessoal…

Começei a estudar java recentemente e estou com um problema.
Não estou conseguindo validar o campo cpf em JSF.

Já procurei outros posts sobre o assunto, segui as orientações, mas ainda sim não consegui fazer a validação.

Se alguém puder me ajudar eu agradeço.

Segui abaixo o código que fiz como teste:

<%@page contentType="text/html" pageEncoding="UTF-8"%>

<%@taglib prefix="f" uri="http://java.sun.com/jsf/core"%>
<%@taglib prefix="h" uri="http://java.sun.com/jsf/html"%>
<%@taglib  uri="http://richfaces.org/rich" prefix="rich"%>
<%@taglib  uri="http://richfaces.org/a4j" prefix="a4j"%>

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
   "http://www.w3.org/TR/html4/loose.dtd">

<%--
    This file is an entry point for JavaServer Faces application.
--%>

    <html>
        <head>
            <meta http-equiv="Content-Type" content="text/html; charset=UTF-8"/>
            <title>JSP Page</title>

            <script src="JS/jquery.js" type="text/javascript"></script>
            <script src="$JS/jquery.validate.js" type="text/javascript"></script>
            <script src="JS/jquery.maskedinput.js" type="text/javascript"></script>


            <script>
             $(documentElement).ready(function() {
                 jQuery(function($){
                    $('#form1\\:cpf').mask("([CPF removido])");
                  });
              });
            </script>

        </head>
        <body>
            <f:view>
                  <h1><h:outputText value="JavaServer Faces"/></h1>           

                   <rich:tabPanel>
                      <rich:tab label="exemplo">

                          <form id="form1">
                                   <h:outputText value="CPF:" />
                                   <h:inputText size="18" id="cpf" value="#{cliente.cliente.cpf}"
                                         required="true"
                                         requiredMessage="Campo obrigatório" label="#F0F0F0">
                                      
                                       <rich:jQuery selector="#cpf" name="cpf" query="mask('[CPF removido]')" timing="immediate"/>
                                  </h:inputText>
                                   <h:message for="cpf"/>
                                  
                                   <h:commandButton value="Salvar" action="#{cliente.salvar}" />
                          </form>
                 
                    </rich:tab>
                  </rich:tabPanel>
            </f:view>
        </body>
    </html>

1 Resposta

yorgan

Você quer validar o CPF ou quer colocar uma mascara no campo?
Se for validar, você pode utilizar a biblioteca da Caelum, Stella.

[]'s
Daniel

Criado 5 de junho de 2010
Ultima resposta 5 de jun. de 2010
Respostas 1
Participantes 2