Formatar campos data e CEP com JSF

Boa tarde

Gostaria de saber como formatar campos de cep e de datas igual quando fazemos com javascript.

ex.

Utilizando a funcao javascript, bastava incluir OnKeyPress=“formatar(this, ‘##/##/####’)” no campo que seria formatado.

Tentei fazer a mesma coisa utilizando-se um
inputText e não funciona…

Existe alguma outra forma de ser fazer isso?? Se existe, podem dar um exemplo por favor??

Obrigado!

Amigo, vc pode fazer um js, e usalo dessa forma:

<h:inputText required="true" maxlength="10" value="#{vendasPorPoloManager.dtInicial}" id="dtInicial" onkeyup="return txtBoxFormat(this, '99/99/9999', event);"> </h:inputText>

o js :


function txtBoxFormat(objeto, sMask, evtKeyPress) {
var i, nCount, sValue, fldLen, mskLen,bolMask, sCod, nTecla;
if(document.all) { // Internet Explorer
nTecla = evtKeyPress.keyCode; }
else if(document.layers) { // Nestcape
nTecla = evtKeyPress.which;
}
sValue = objeto.value;
// Limpa todos os caracteres de formatação que
// já estiverem no campo.
sValue = sValue.toString().replace( "-", "" );
sValue = sValue.toString().replace( "-", "" );
sValue = sValue.toString().replace( ".", "" );
sValue = sValue.toString().replace( ".", "" );
sValue = sValue.toString().replace( "/", "" );
sValue = sValue.toString().replace( "/", "" );
sValue = sValue.toString().replace( ":", "" );
sValue = sValue.toString().replace( ":", "" );
sValue = sValue.toString().replace( "(", "" );
sValue = sValue.toString().replace( "(", "" );
sValue = sValue.toString().replace( ")", "" );
sValue = sValue.toString().replace( ")", "" );
sValue = sValue.toString().replace( " ", "" );
sValue = sValue.toString().replace( " ", "" );
fldLen = sValue.length;
mskLen = sMask.length;
i = 0;
nCount = 0;
sCod = "";
mskLen = fldLen;
while (i <= mskLen) {
bolMask = ((sMask.charAt(i) == "-") || (sMask.charAt(i) == ".") || (sMask.charAt(i) == "/") || (sMask.charAt(i) == ":"))
bolMask = bolMask || ((sMask.charAt(i) == "(") || (sMask.charAt(i) == ")") || (sMask.charAt(i) == " "))
if (bolMask) {
sCod += sMask.charAt(i);
mskLen++; }
else {
sCod += sValue.charAt(nCount);
nCount++;
}
i++;
}
objeto.value = sCod;
if (nTecla != 8) { // backspace
if (sMask.charAt(i-1) == "9") { // apenas números...
return ((nTecla > 47) && (nTecla < 58)); } // números de 0 a 9
else { // qualquer caracter...
return true;
} }
else {
return true;
}
}

ai no seu onkeyup=“return txtBoxFormat(this, ‘99/99/9999’, event);” vc pode colocar o formato que vc quer, por exemplo,
CEP: (this, ‘99999-999’, event);

ok?

qualquer coisa da um toque

abraços