JSF - Inputs com formato, por ex cpf: 999.999.999-99

6 respostas
M

Colegas,

O vocês indicam para formatação de campos Text Input do tipo: cpf, data e entre outros, no jsf?

Muito obrigado,

Marques

6 Respostas

D

Vc está usando richfaces ou a4j???
Se sim faça o salve o arquivo do post em pasta depois adicione ao seu projeto:

<f:view>
          <a4j:form> 
    <a4j:loadScript src="pasta que vc salvou o arquivo /jquery.maskedinput-1.1.4.pack.js" />  
         <h:inputText id="cpf" size="5">
                          <rich:jQuery selector="#cpf" query="mask('[CPF removido]')" timing="onload" /> 
       </h:inputText>
 </a4j:form>  
  </f:view>

Se não der certo por favor poste.

R

Acho que basicamente trabalhar com jsf-converters e jquery resolve muito bem o problema!
Abraços e boa sorte.

J

Daniel.F,

valeu pela dica. Funcionou perfeitamente para o que eu estava precisando…

:slight_smile:

C

Apesar de reproduzir o código postado, a máscara CNPJ do código a seguir não funciona. Alguém poderia dar um help.

Valeu!!!

<h:outputText value="CNPJ" />
<a4j:form >
<a4j:loadScript src="cfg/jquery.maskedinput-1.1.4.pack.js" />
<h:inputText id="cnpj" required="true"
         value="#{ManagerBean.empresa.cnpj}" style="width:160px;" >
<rich:jQuery selector="#cnpj" query="mask('99.999.999/9999-99')" timing="onload" />
</h:inputText>
</a4j:form>

A seguir vai o código todo....

<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<%@ page language="java" contentType="text/html; charset=ISO-8859-1"
    pageEncoding="ISO-8859-1" %>
<%@ taglib uri="http://java.sun.com/jsf/core" prefix="f" %>
<%@ taglib uri="http://java.sun.com/jsf/html" prefix="h" %>
<%@ taglib uri="http://richfaces.org/rich" prefix="rich" %>
<%@ taglib uri="http://richfaces.org/a4j" prefix="a4j" %>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
<title>Sistema de Controle de Equipamentos</title>

<link rel="stylesheet" href="estilo.css" type="text/css">

</head>
<body>

<div id="container">

<div id="topo">
<img src="Logo_PRF.bmp" width="80" height="92" align="left"></img>
<h3>Seção Administrativa e Financeira - 5ª SRPRF/RJ<br>
            Sistema de Controle de Equipamentos</h3>
</div>

<div id="coluna">
</div>

<div id="conteudo">

<f:view>
<h:outputText value="Cadastra Empresas - Fabricantes/Manutenção"
        style="font-weight:bold; margin-left:250px;"/>
<h:form id="form2">
<fieldset id="grupo2" >
<legend>Dados do Empresa</legend>
<h:panelGrid columns="4" cellspacing="7" >
<h:outputText value="Empresa" />
<h:inputText value="#{ManagerBean.empresa.empresa}" tabindex="1" style="width:350px;" />
<h:outputText value="CNPJ" />
<a4j:form >
<a4j:loadScript src="cfg/jquery.maskedinput-1.1.4.pack.js" />
<h:inputText id="cnpj" required="true"
         value="#{ManagerBean.empresa.cnpj}" style="width:160px;" >
<rich:jQuery selector="#cnpj" query="mask('99.999.999/9999-99')" timing="onload" />
</h:inputText>
</a4j:form>
<h:outputText value="Endereço" />
<h:inputText value="#{ManagerBean.empresa.endempr}" style="width:350px;" />
<h:outputText value="Nº" />
<h:inputText value="#{ManagerBean.empresa.nrempr}" style="width:70px;" />
<h:outputText value="Complemento" />
<h:inputText value="#{ManagerBean.empresa.complempr}" style="width:250px;" />
<h:outputText value="Bairro" />
<h:inputText value="#{ManagerBean.empresa.bairroempr}" style="width:150px;" />
<h:outputText value="Cidade" />
<h:inputText value="#{ManagerBean.empresa.cidadeempr}" style="width:250px;" />

<h:outputText value="UF" />
<h:selectOneMenu value="#{ManagerBean.empresa.idufempresa}" style="width:50px;" >
<f:selectItem itemValue="1" itemLabel="AL" />
<f:selectItem itemValue="2" itemLabel="BA" />
<f:selectItem itemValue="2" itemLabel="CE" />
</h:selectOneMenu>
<h:outputText value="CEP" />
<h:inputText value="#{ManagerBean.empresa.cepempr}" style="width:100px; " />
</h:panelGrid>
</fieldset>

<fieldset id="grupo3">
<legend>Contato/Tipo de Empresa</legend>
<h:panelGrid columns="6" cellspacing="7" >
<h:outputText value="Telefone" />
<h:inputText value="#{ManagerBean.empresa.telempr}" style="width:120px;" />
<h:panelGroup>
<h:outputText value="Fax  " />
<h:inputText value="#{ManagerBean.empresa.faxempr}" style="width:120px;" />
</h:panelGroup>
<h:outputText />
<h:panelGroup>
<h:outputText value="Email  " style="text-align:right;"/>
<h:inputText value="#{ManagerBean.empresa.emailempr}" style="width:200px;" />
</h:panelGroup>
<h:outputText />

<h:outputText value="Contato" />
<h:inputText value="#{ManagerBean.empresa.contatoempr}" style="width:120px;" />
<h:panelGroup>
<h:outputText value="Fabricante " />
<h:selectBooleanCheckbox value="#{ManagerBean.empresa.fabr}" />
</h:panelGroup>
<h:outputText />

<h:panelGroup>
<h:outputText value="Manutenção " />
<h:selectBooleanCheckbox value="#{ManagerBean.empresa.manut}" />
</h:panelGroup>
<h:outputText />

</h:panelGrid>
</fieldset>
<h:commandButton value=" Gravar " styleClass="btposfieldset1"/>
<h:commandButton value=" Limpar " styleClass="btposfieldset1"/>
<h:commandButton value="   Sair   " styleClass="btposfieldset1"/>
</h:form>

</f:view>

</div>

<div id="rodape">
</div>

</div>

</body>
</html>
C

Sobe…

C

Alguém pode dar uma ajuda??? Valeu!!!

Criado 17 de abril de 2009
Ultima resposta 2 de mar. de 2011
Respostas 6
Participantes 5