Jquery com richface

Pessoal queria saber como em um mesmo campo eu consigo alternar as mascaras de acordo com um radio button…
No meu caso é alternar entre a mascara de CPF e CNPJ.

Obrigado !!!

Segue meu código:

	<h:form id="frmPesquisaCliente" >
		<rich:panel id="pnlPesquisaCliente">
			<f:facet name="header">
				<h:outputLabel value="Buscar Cliente"/>
			</f:facet>
			
			<h:selectOneRadio id="rdTipoPessoa" onclick="trocaLabelPessoa(this)">
				<f:selectItem id="itemPj"  itemValue="PJ" itemLabel="Pessoa Jurídica"/>
				<f:selectItem id="itemPf"  itemValue="PF" itemLabel="Pessoa Física" />
				<a4j:support reRender="clebio"
							 event="onclick"  />							 
			</h:selectOneRadio>
			
			<hr style="color: gray"/>
			
			<a4j:outputPanel id="clebio">
			<h:panelGrid id="pnlGridPesquisaCliente" columns="2" >				
				<h:outputLabel for="itCpf"  id="lbCpfCnpj"  value="fud"/>							
				
				<h:inputText id="itCpf" maxlength="11" value="#{atendimentoHandler.buscaDocumento}">					

--------------------------------------------------------------------------------------------------------------------------------------------
--MASCARA QUE DEVE SER DINAMICA(CPF/CNPJ)

					<rich:jQuery id="mascaraCpf" selector="#itCpf"  
								 query="setMask();" timing="onload"/>
--------------------------------------------------------------------------------------------------------------------------------------------
				</h:inputText>
							
				<h:outputLabel for="itNomeRazao" value="Nome / R.Social"/>
				<h:inputText id="itNomeRazao" size="47" value=""/>
												
				<h:outputLabel for="buscaTelefone" value="Telefone"/>
				<h:panelGroup>
					<h:selectOneMenu id="buscaDdd" value="#{atendimentoHandler.buscaDdd}">
						<s:selectItems value="#{atendimentoHandler.ddds}"
							var="ddd" noSelectionLabel="" label="#{ddd}" itemValue="#{ddd}"/>
					</h:selectOneMenu>
					<h:inputText id="buscaTelefone" value="#{atendimentoHandler.buscaTelefone}" style="width: 110px">
						<rich:jQuery id="mascaraBuscaTelefone" selector="#buscaTelefone" 
									 query="setMask('rrrrrrrrrrrrrrr');" timing="onload"/>
					</h:inputText>
				</h:panelGroup>				
			</h:panelGrid>

			</a4j:outputPanel>

[quote=clebiovieira]Pessoal queria saber como em um mesmo campo eu consigo alternar as mascaras de acordo com um radio button…
No meu caso é alternar entre a mascara de CPF e CNPJ.

Obrigado !!!

Segue meu código:

[code]
<h:form id=“frmPesquisaCliente” >
<rich:panel id=“pnlPesquisaCliente”>
<f:facet name=“header”>
<h:outputLabel value=“Buscar Cliente”/>
</f:facet>

		&lt;h:selectOneRadio id="rdTipoPessoa" onclick="trocaLabelPessoa(this)"&gt;
			&lt;f:selectItem id="itemPj"  itemValue="PJ" itemLabel="Pessoa Jurídica"/&gt;
			&lt;f:selectItem id="itemPf"  itemValue="PF" itemLabel="Pessoa Física" /&gt;
			&lt;a4j:support reRender="clebio"
						 event="onclick"  /&gt;							 
		&lt;/h:selectOneRadio&gt;
		
		&lt;hr style="color: gray"/&gt;
		
		&lt;a4j:outputPanel id="clebio"&gt;
		&lt;h:panelGrid id="pnlGridPesquisaCliente" columns="2" &gt;				
			&lt;h:outputLabel for="itCpf"  id="lbCpfCnpj"  value="fud"/&gt;							
			
			&lt;h:inputText id="itCpf" maxlength="11" value="#{atendimentoHandler.buscaDocumento}"&gt;					

–MASCARA QUE DEVE SER DINAMICA(CPF/CNPJ)

				&lt;rich:jQuery id="mascaraCpf" selector="#itCpf"  
							 query="setMask();" timing="onload"/&gt;

			&lt;/h:inputText&gt;
						
			&lt;h:outputLabel for="itNomeRazao" value="Nome / R.Social"/&gt;
			&lt;h:inputText id="itNomeRazao" size="47" value=""/&gt;
											
			&lt;h:outputLabel for="buscaTelefone" value="Telefone"/&gt;
			&lt;h:panelGroup&gt;
				&lt;h:selectOneMenu id="buscaDdd" value="#{atendimentoHandler.buscaDdd}"&gt;
					&lt;s:selectItems value="#{atendimentoHandler.ddds}"
						var="ddd" noSelectionLabel="" label="#{ddd}" itemValue="#{ddd}"/&gt;
				&lt;/h:selectOneMenu&gt;
				&lt;h:inputText id="buscaTelefone" value="#{atendimentoHandler.buscaTelefone}" style="width: 110px"&gt;
					&lt;rich:jQuery id="mascaraBuscaTelefone" selector="#buscaTelefone" 
								 query="setMask('rrrrrrrrrrrrrrr');" timing="onload"/&gt;
				&lt;/h:inputText&gt;
			&lt;/h:panelGroup&gt;				
		&lt;/h:panelGrid&gt;

		&lt;/a4j:outputPanel&gt;

[/code][/quote]

Caro clebio, tente fazer o seguinte:

&lt;h:selectOneRadio id="rdTipoPessoa" onclick="trocaLabelPessoa(this)" value="#{atendimentoHandler.tipoPessoa}"&gt;  
   &lt;f:selectItem id="itemPj"  itemValue="PJ" itemLabel="Pessoa Jurídica"/&gt;  
   &lt;f:selectItem id="itemPf"  itemValue="PF" itemLabel="Pessoa Física" /&gt;  
   &lt;a4j:support ajaxSingle="true" reRender="clebio" event="onclick"  /&gt;                            
&lt;/h:selectOneRadio&gt;

&lt;h:outputLabel for="itCpf"  id="lbCpfCnpj"  value="fud"/&gt;
&lt;h:inputText id="itCpf" maxlength="11" value="#{atendimentoHandler.buscaDocumento}"&gt;
&lt;h:panelGroup id="clebio"&gt;
   &lt;rich:jQuery id="mascaraCpf" selector="#itCpf" query="setMask('999.999.999-99');" timing="immediate" rendered="#{atendimentoHandler.tipoPessoa eq 'PF'}"/&gt;
   &lt;rich:jQuery id="mascaraCnpj" selector="#itCpf" query="setMask('99.999.999/9999-99');" timing="immediate" rendered="#{atendimentoHandler.tipoPessoa eq 'PJ'}"/&gt;
&lt;/h:panelGroup&gt;