JSF 2 + PrimeFaces + Ajax

Boa noite a todos, tenho na página CadastrarCliente.xhtml um h:selectOneRadio de controle se o formulário será de pessoa jurídica ou pessoa física. Caso o radio selecionado seja de PJ, devo renderizar o componente p:inputMask relacionado a máscara do CNPJ, senão se for selecionado PF, devo renderizar o componente p:inputMask relacionado porém não sei como fazer isto sem ter que fazer um submit na minha página, coisa que não quero fazer! Quero que os componentes sejam redenrizados dinamicamente assim que o usuário clicar no radiobuttom que deseja cadastrar. Como faço isso?

CadastrarCliente.xhtml

[code]<?xml version='1.0' encoding='UTF-8' ?>

<ui:composition template=“principal.xhtml”
xmlns=“http://www.w3.org/1999/xhtml
xmlns:ui=“http://java.sun.com/jsf/facelets
xmlns:h=“http://java.sun.com/jsf/html
xmlns:f=“http://java.sun.com/jsf/core
xmlns:p=“http://primefaces.prime.com.tr/ui”>

<ui:define name="conteudo">
	<h:form prependId="false">
	  <p:tabView>
	  	<p:tab title="Cadastro" id="tabCadastroCliente">
	  		<h:panelGrid id="gridCadastro" columns="5" cellspacing="5">
	  			<!-- LINHA 1 -->
		  		<h:selectOneRadio id="tipoPessoa" value="#{clienteBean.tpPessoa}" immediate="true">
		  			<f:selectItem itemLabel="Pessoa Física" itemValue="PF"/>
		  			<f:selectItem itemLabel="Pessoa Jurídica" itemValue="PJ"/><!--
		  			<f:ajax event="click" render="cliCPF, cliCNPJ" /> 
		  		--></h:selectOneRadio>
		  		<h:outputLabel id="vazio1" value=""/>
				<h:outputLabel id="vazio2" value=""/>
		  		<h:outputLabel id="vazio3" value=""/>
		  		<h:outputLabel id="vazio4" value=""/>
				
				<!-- LINHA 2 -->
		  		<h:outputLabel id="labelCliNome" value="Nome: * "/>
		  		<h:outputLabel id="labelCpfCnpj" value="CPF/CNPJ: * "/>
		  		<h:outputLabel id="labelCliTel" value="Telefone: "/>
		  		<h:outputLabel id="labelCliCel" value="Celular: "/>
		  		<h:outputLabel id="labelCliEmail" value="E-Mail: "/>
		  		
		  		<p:inputText id="cliNome" required="true" maxlength="50" size="35" value="#{clienteBean.pessoa.nome}"/>
		  		<p:inputMask mask="999.999.999.99" id="cliCPF" value="#{clienteBean.pessoa.CpfCnpj}" 
		  		rendered="#{clienteBean.tpPessoa == 'PF'}"/>
		  		<p:inputMask mask="99.999.999/9999-99" id="cliCNPJ" value="#{clienteBean.pessoa.CpfCnpj}"
		  		rendered="#{clienteBean.tpPessoa == 'PJ'}"/>
		  		<p:inputMask mask="(99)9999-9999" id="cliTel" size="10" value="#{clienteBean.pessoa.telefone}"/>
		  		<p:inputMask mask="(99)9999-9999" id="cliCel" size="10" value="#{clienteBean.pessoa.celular}"/>
		  		<p:inputText id="cliEmail" maxlength="120" size="45" value="#{clienteBean.pessoa.email}"/>
		  		
		  		<!-- LINHA 3 -->
	  		</h:panelGrid>  		
	  	</p:tab>
	  </p:tabView>
	</h:form>
</ui:define>

</ui:composition>
[/code]

Olá Gabriel! Eu já fiz isso mas em vez de ser rádio eu usei combo, mas é só questão de adaptação, vou colocar os trechos importantes:

cliente.xhtml

&lt;h:selectOneMenu id="tipoPessoa" value="#{clienteBean.cliente.tipoPessoa}" valueChangeListener="#{clienteBean.trocaMascara}" &gt;
    &lt;f:selectItems value="#{listasUtil.tipoPessoa}" /&gt;
    &lt;f:ajax event="change" render="txtCpfCnpj" /&gt;
&lt;/h:selectOneMenu&gt;

&lt;p:outputPanel id="txtCpfCnpj" &gt;
    &lt;partner:inputMask label="CPF/CNPJ" id="CpfCnpj" value="#{clienteBean.cliente.cpfCnpj}" mask="#{clienteBean.mascaraCpfCnpj}" /&gt;
&lt;/p:outputPanel&gt;

E no ClienteBean.java

private String mascaraCpfCnpj = "999.999.999-99";
private Cliente cliente = new Cliente();

public void trocaMascara(ValueChangeEvent event) {
    String tipo = event.getNewValue().toString();
    if (tipo.equals("J")) {
        mascaraCpfCnpj = "99.999.999/9999-99";
    } else {
        mascaraCpfCnpj = "999.999.999-99";
    }
}

//Getters e Setters para cliente e mascaraCpfCnpj

Observação, quanto ao escopo use um acima do Request … se não me engano não funciona direito com Request…

:slight_smile:

andii obrigado pela ajuda, adaptei o meu código para algo próximo do seu mas continuo sem sucesso!
Alguem mais sabe como posso fazer isto?

Alguem ai que conhece me ajuda sobre o assunto! O meu código até o momento está da seguinte forma e eu não sei o que está errado ou faltando:

FormPessoa.xhtml

[code]<ui:composition template="/paginas/principal.xhtml">
<ui:define name=“conteudo”>
<h:form prependId=“false”>
<p:tabView>
<p:tab title=“Cadastro” id=“tabCadastroCliente”>

		  		<h:panelGrid columns="2" cellspacing="1">
					<h:selectOneRadio id="tipoPessoa" immediate="true" value="{#pessoaBean.tpPessoa}"> 
						<f:selectItem itemLabel="Pessoa Física" itemValue="PF" />
						<f:selectItem itemLabel="Pessoa Jurídica" itemValue="PJ" />
						<p:ajax event="change" update="pesCPF pesCNPJ" listener="#{clienteBean.alterarTpPessoa}"/>
					</h:selectOneRadio>
				</h:panelGrid>
					
				<h:panelGrid columns="5" cellpadding="2">
					<h:outputLabel id="labelCliNome" value="Nome: "/>
			  		<h:outputLabel id="labelCpfCnpj" value="CPF/CNPJ: "/>
			  		<h:outputLabel id="labelCliTel" value="Telefone: "/>
			  		<h:outputLabel id="labelCliCel" value="Celular: "/>
			  		<h:outputLabel id="labelCliEmail" value="E-Mail: "/>
			  		<p:inputText id="pesNome" required="true" maxlength="50" size="35" value="#{pessoaBean.pessoa.nome}"/>
			  		<p:inputMask mask="999.999.999.99" id="pesCPF" value="#{pessoaBean.pessoa.CpfCnpj}" rendered="#{pessoaBean.tpPessoa == 'PF'}"/>
			  		<p:inputMask mask="99.999.999/9999-99" id="pesCNPJ" value="#{pessoaBean.pessoa.CpfCnpj}" rendered="#{pessoaBean.tpPessoa == 'PJ'}"/>
			  		<p:inputMask mask="(99)9999-9999" id="pesTel" size="10" value="#{pessoaBean.pessoa.telefone}"/>
			  		<p:inputMask mask="(99)9999-9999" id="pesCel" size="10" value="#{pessoaBean.pessoa.celular}"/>
			  		<p:inputText id="pesEmail" maxlength="80" size="35" value="#{pessoaBean.pessoa.email}"/>
				</h:panelGrid>
			  		
				<h:panelGrid columns="4" cellpadding="2">
					<h:outputLabel id="labelLogradouro" value="Logradouro: "/>
			  		<h:outputLabel id="labelNrLogradouro" value="Nro:  "/>
			  		<h:outputLabel id="labelCep" value="CEP: "/>
			  		<h:outputLabel id="labelBairro" value="Bairro: *"/>
	  		  		<p:inputText id="pesLogradouro" required="true" maxlength="50" size="35" value="#{pessoaBean.pessoa.logradouro}"/>
			  		<p:inputMask mask="9999" id="pesNrLogradouro" required="true" size="5" value="#{pessoaBean.pessoa.nrLogradouro}"/>
			  		<p:inputMask mask="99.999-999" id="pesCep" required="true" size="10" value="#{pessoaBean.pessoa.cep}" />
			  		<p:inputText id="pesBairro" required="true" maxlength="35" size="35" value="#{pessoaBean.pessoa.bairro}"/>
				</h:panelGrid>	
			  		
				<h:panelGrid columns="2" cellpadding="2">
					<h:outputLabel id="labelCidade" value="Cidade: "/>
			  		<h:outputLabel id="labelEstado" value="Estado: "/>				  		
			  		<p:inputText id="pesCidade" required="true" maxlength="35" size="35" value="#{pessoaBean.pessoa.cidade}" />
			  		<p:inputText id="pesEstadp" required="true" maxlength="35" size="35" value="#{pessoaBean.pessoa.estado}"/> 		
				</h:panelGrid>
			  		
		  	</p:tab>
		  </p:tabView>
		</h:form>
	</ui:define>
</ui:composition>[/code]

PessoaMB.java

[code]@ManagedBean(name=“pessoaBean”)
@SessionScoped
public class PessoaMB {

private Pessoa pessoa;
private Cliente cliente;
private String tpPessoa = "PF";

public void alterarTpPessoa(ValueChangeEvent evt){
	this.setTpPessoa(evt.getNewValue().toString());	
}

//getters and setters
[/code]

Gabriel,

tente fazer isso:

rendered="#{pessoaBean.tpPessoa eq 'PJ'}"

ao invés disso:

rendered="#{pessoaBean.tpPessoa == 'PJ'}"

Outra dica, tente utilizar o f:ajax, o p:ajax funciona corretamente, só que o f:ajax é muito mais rapido pois é ajax nativo do JSF2!!

Outra coisa, você pode usar o ViewScoped no lugar de SessionScoped que funcionará normalmente também!

xD~~

Vlw as dicas cara vou testar aqui!
:smiley:

O que que tem de errado no meu código que quando eu seleciono um dos rádio ele n renderiza o meu <h:form id=“formCadastroPessoa” rendered="#{pessoaBean.itemSelecionado.getValue() != null}" >
???

obs.: eu já debuguei os métodos no meu managebean e ta tudo ok por la, setando os valores corretos e tudo mais.

formpessoa.xhtml

<?xml version='1.0' encoding='UTF-8' ?>
<!DOCTYPE composition PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml"
	xmlns:ui="http://java.sun.com/jsf/facelets"
	xmlns:h="http://java.sun.com/jsf/html"
	xmlns:f="http://java.sun.com/jsf/core"
	xmlns:p="http://primefaces.prime.com.tr/ui">

	<ui:composition template="/paginas/principal.xhtml">	
		<ui:define name="conteudo">
			<h:form prependId="false">
			  <p:tabView>
			  	<p:tab title="Cadastro" id="tabCadastroCliente">
			  	
			  		<h:panelGrid columns="2" cellspacing="1">
						<h:selectOneRadio id="tipoPessoa" immediate="true" value="{#pessoaBean.tpPessoa}" valueChangeListener="#{pessoaBean.alterarTpPessoa}"> 
							<f:selectItems value="#{pessoaBean.tpPessoa}" />
							<f:ajax  event="change" render="formCadastroPessoa" />
							<!-- <p:ajax  event="change" update="formCadastroPessoa" /> -->
						</h:selectOneRadio>
					</h:panelGrid>
					
					<h:form id="formCadastroPessoa" rendered="#{pessoaBean.itemSelecionado.getValue() != null}" >		
						<p:ajaxStatus style="width:16px;height:16px;">
							<f:facet name="start">
								<h:graphicImage value="images/loading.gif" />
							</f:facet>
							<f:facet name="complete">
								<h:outputText value="" />
							</f:facet>
						</p:ajaxStatus>						
						<h:panelGrid columns="5" cellpadding="2" >
							<h:outputLabel id="labelCliNome" value="Nome: "/>
					  		<h:outputLabel id="labelCpfCnpj" value="CPF/CNPJ: "/>
					  		<h:outputLabel id="labelCliTel" value="Telefone: "/>
					  		<h:outputLabel id="labelCliCel" value="Celular: "/>
					  		<h:outputLabel id="labelCliEmail" value="E-Mail: "/>
					  		<p:inputText id="pesNome" required="true" maxlength="50" size="35" value="#{pessoaBean.pessoa.nome}"/>
					  		<p:inputMask mask="#{pessoaBean.trocarMascara()}" id="pesCpfCnpj" value="#{pessoaBean.pessoa.CpfCnpj}"/>
					  		<p:inputMask mask="(99)9999-9999" id="pesTel" size="10" value="#{pessoaBean.pessoa.telefone}"/>
					  		<p:inputMask mask="(99)9999-9999" id="pesCel" size="10" value="#{pessoaBean.pessoa.celular}"/>
					  		<p:inputText id="pesEmail" maxlength="80" size="35" value="#{pessoaBean.pessoa.email}"/>
						</h:panelGrid>
					  		
						<h:panelGrid columns="4" cellpadding="2">
							<h:outputLabel id="labelLogradouro" value="Logradouro: "/>
					  		<h:outputLabel id="labelNrLogradouro" value="Nro:  "/>
					  		<h:outputLabel id="labelCep" value="CEP: "/>
					  		<h:outputLabel id="labelBairro" value="Bairro: *"/>
			  		  		<p:inputText id="pesLogradouro" required="true" maxlength="50" size="35" value="#{pessoaBean.pessoa.logradouro}"/>
					  		<p:inputMask mask="9999" id="pesNrLogradouro" required="true" size="5" value="#{pessoaBean.pessoa.nrLogradouro}"/>
					  		<p:inputMask mask="99.999-999" id="pesCep" required="true" size="10" value="#{pessoaBean.pessoa.cep}" />
					  		<p:inputText id="pesBairro" required="true" maxlength="35" size="35" value="#{pessoaBean.pessoa.bairro}"/>
						</h:panelGrid>	
					  		
						<h:panelGrid columns="2" cellpadding="2">
							<h:outputLabel id="labelCidade" value="Cidade: "/>
					  		<h:outputLabel id="labelEstado" value="Estado: "/>				  		
					  		<p:inputText id="pesCidade" required="true" maxlength="35" size="35" value="#{pessoaBean.pessoa.cidade}" />
					  		<p:inputText id="pesEstadp" required="true" maxlength="35" size="35" value="#{pessoaBean.pessoa.estado}"/> 		
						</h:panelGrid>
					</h:form>
			  	</p:tab>
			  </p:tabView>
			</h:form>
		</ui:define>
	</ui:composition>
</html>

pessoamb.java

[code]package br.com.spa.controller;

import java.util.ArrayList;
import java.util.EventListener;
import java.util.List;

import javax.faces.bean.ManagedBean;
import javax.faces.bean.SessionScoped;
import javax.faces.event.ActionEvent;
import javax.faces.event.ValueChangeEvent;
import javax.faces.model.SelectItem;

import br.com.spa.model.bean.Cliente;
import br.com.spa.model.bean.Pessoa;

@ManagedBean(name=“pessoaBean”)
@SessionScoped
public class PessoaMB {

private Pessoa pessoa;
private Cliente cliente;
private SelectItem itemSelecionado;
private List<SelectItem> tpPessoa;
private String mascaraCpfCnpj;



public PessoaMB(){
	itemSelecionado = new SelectItem();
	tpPessoa = new ArrayList<SelectItem>();
	tpPessoa.add(new SelectItem("PF", "Pessoa Física"));
	tpPessoa.add(new SelectItem("PJ", "Pessoa Jurídica"));
}

public void alterarTpPessoa(ValueChangeEvent evt){
	itemSelecionado.setValue(evt.getNewValue());
}

public void trocarMascara(){
	if(itemSelecionado.getValue() != null){
		String tipo = itemSelecionado.getValue().toString();
		if (tipo.equals("PJ")) {  
	        mascaraCpfCnpj = "99.999.999/9999-99";  
	    } else {  
	        mascaraCpfCnpj = "999.999.999-99";  
	    }  
	}		
}


public Pessoa getPessoa() {
	return pessoa;
}

public void setPessoa(Pessoa pessoa) {
	this.pessoa = pessoa;
}

public Cliente getCliente() {
	return cliente;
}

public void setCliente(Cliente cliente) {
	this.cliente = cliente;
}

public SelectItem getItemSelecionado() {
	return itemSelecionado;
}

public void setItemSelecionado(SelectItem itemSelecionado) {
	this.itemSelecionado = itemSelecionado;
}

public List<SelectItem> getTpPessoa() {
	return tpPessoa;
}

public void setTpPessoa(List<SelectItem> tpPessoa) {
	this.tpPessoa = tpPessoa;
}

public String getMascaraCpfCnpj() {
	return mascaraCpfCnpj;
}

public void setMascaraCpfCnpj(String mascaraCpfCnpj) {
	this.mascaraCpfCnpj = mascaraCpfCnpj;
}

}
[/code]

Tente:

rendered="#{pessoaBean.itemSelecionado.getValue() ne null}

tentei, n funcionou! ;/

Olá!!
Só tive tempo de examinar o código agora, mas dá um olhada que o meu:

&lt;p:inputMask mask="#{pessoaBean.mascaraCpfCnpj}" id="pesCpfCnpj" value="#{pessoaBean.pessoa.CpfCnpj}"/&gt; 

ele precisa estar dentro do outputPanel, assim:

&lt;p:outputPanel id="txtCpfCnpj" &gt;
       &lt;p:inputMask mask="#{pessoaBean.mascaraCpfCnpj}" id="pesCpfCnpj" value="#{pessoaBean.pessoa.CpfCnpj}"/&gt; 
&lt;/p:outputPanel&gt; 

e veja que eu mando atualizar o outputPanel e não o form!!

outro detalhe… vc está chamando o metodo na propriedade mask… não é isso, vc tem que chamar o get/set da String mascaraCpfCnpj

[quote=Gabriel Garcia]O que que tem de errado no meu código que quando eu seleciono um dos rádio ele n renderiza o meu <h:form id=“formCadastroPessoa” rendered="#{pessoaBean.itemSelecionado.getValue() != null}" >
???

obs.: eu já debuguei os métodos no meu managebean e ta tudo ok por la, setando os valores corretos e tudo mais.

formpessoa.xhtml

<?xml version='1.0' encoding='UTF-8' ?>
<!DOCTYPE composition PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml"
	xmlns:ui="http://java.sun.com/jsf/facelets"
	xmlns:h="http://java.sun.com/jsf/html"
	xmlns:f="http://java.sun.com/jsf/core"
	xmlns:p="http://primefaces.prime.com.tr/ui">

	<ui:composition template="/paginas/principal.xhtml">	
		<ui:define name="conteudo">
			<h:form prependId="false">
			  <p:tabView>
			  	<p:tab title="Cadastro" id="tabCadastroCliente">
			  	
			  		<h:panelGrid columns="2" cellspacing="1">
						<h:selectOneRadio id="tipoPessoa" immediate="true" value="{#pessoaBean.tpPessoa}" valueChangeListener="#{pessoaBean.alterarTpPessoa}"> 
							<f:selectItems value="#{pessoaBean.tpPessoa}" />
							<f:ajax  event="change" render="formCadastroPessoa" />
							<!-- <p:ajax  event="change" update="formCadastroPessoa" /> -->
						</h:selectOneRadio>
					</h:panelGrid>
					
					<h:form id="formCadastroPessoa" rendered="#{pessoaBean.itemSelecionado.getValue() != null}" >		
						<p:ajaxStatus style="width:16px;height:16px;">
							<f:facet name="start">
								<h:graphicImage value="images/loading.gif" />
							</f:facet>
							<f:facet name="complete">
								<h:outputText value="" />
							</f:facet>
						</p:ajaxStatus>						
						<h:panelGrid columns="5" cellpadding="2" >
							<h:outputLabel id="labelCliNome" value="Nome: "/>
					  		<h:outputLabel id="labelCpfCnpj" value="CPF/CNPJ: "/>
					  		<h:outputLabel id="labelCliTel" value="Telefone: "/>
					  		<h:outputLabel id="labelCliCel" value="Celular: "/>
					  		<h:outputLabel id="labelCliEmail" value="E-Mail: "/>
					  		<p:inputText id="pesNome" required="true" maxlength="50" size="35" value="#{pessoaBean.pessoa.nome}"/>
					  		<p:inputMask mask="#{pessoaBean.trocarMascara()}" id="pesCpfCnpj" value="#{pessoaBean.pessoa.CpfCnpj}"/>
					  		<p:inputMask mask="(99)9999-9999" id="pesTel" size="10" value="#{pessoaBean.pessoa.telefone}"/>
					  		<p:inputMask mask="(99)9999-9999" id="pesCel" size="10" value="#{pessoaBean.pessoa.celular}"/>
					  		<p:inputText id="pesEmail" maxlength="80" size="35" value="#{pessoaBean.pessoa.email}"/>
						</h:panelGrid>
					  		
						<h:panelGrid columns="4" cellpadding="2">
							<h:outputLabel id="labelLogradouro" value="Logradouro: "/>
					  		<h:outputLabel id="labelNrLogradouro" value="Nro:  "/>
					  		<h:outputLabel id="labelCep" value="CEP: "/>
					  		<h:outputLabel id="labelBairro" value="Bairro: *"/>
			  		  		<p:inputText id="pesLogradouro" required="true" maxlength="50" size="35" value="#{pessoaBean.pessoa.logradouro}"/>
					  		<p:inputMask mask="9999" id="pesNrLogradouro" required="true" size="5" value="#{pessoaBean.pessoa.nrLogradouro}"/>
					  		<p:inputMask mask="99.999-999" id="pesCep" required="true" size="10" value="#{pessoaBean.pessoa.cep}" />
					  		<p:inputText id="pesBairro" required="true" maxlength="35" size="35" value="#{pessoaBean.pessoa.bairro}"/>
						</h:panelGrid>	
					  		
						<h:panelGrid columns="2" cellpadding="2">
							<h:outputLabel id="labelCidade" value="Cidade: "/>
					  		<h:outputLabel id="labelEstado" value="Estado: "/>				  		
					  		<p:inputText id="pesCidade" required="true" maxlength="35" size="35" value="#{pessoaBean.pessoa.cidade}" />
					  		<p:inputText id="pesEstadp" required="true" maxlength="35" size="35" value="#{pessoaBean.pessoa.estado}"/> 		
						</h:panelGrid>
					</h:form>
			  	</p:tab>
			  </p:tabView>
			</h:form>
		</ui:define>
	</ui:composition>
</html>

pessoamb.java

[code]package br.com.spa.controller;

import java.util.ArrayList;
import java.util.EventListener;
import java.util.List;

import javax.faces.bean.ManagedBean;
import javax.faces.bean.SessionScoped;
import javax.faces.event.ActionEvent;
import javax.faces.event.ValueChangeEvent;
import javax.faces.model.SelectItem;

import br.com.spa.model.bean.Cliente;
import br.com.spa.model.bean.Pessoa;

@ManagedBean(name=“pessoaBean”)
@SessionScoped
public class PessoaMB {

private Pessoa pessoa;
private Cliente cliente;
private SelectItem itemSelecionado;
private List<SelectItem> tpPessoa;
private String mascaraCpfCnpj;



public PessoaMB(){
	itemSelecionado = new SelectItem();
	tpPessoa = new ArrayList<SelectItem>();
	tpPessoa.add(new SelectItem("PF", "Pessoa Física"));
	tpPessoa.add(new SelectItem("PJ", "Pessoa Jurídica"));
}

public void alterarTpPessoa(ValueChangeEvent evt){
	itemSelecionado.setValue(evt.getNewValue());
}

public void trocarMascara(){
	if(itemSelecionado.getValue() != null){
		String tipo = itemSelecionado.getValue().toString();
		if (tipo.equals("PJ")) {  
	        mascaraCpfCnpj = "99.999.999/9999-99";  
	    } else {  
	        mascaraCpfCnpj = "999.999.999-99";  
	    }  
	}		
}


public Pessoa getPessoa() {
	return pessoa;
}

public void setPessoa(Pessoa pessoa) {
	this.pessoa = pessoa;
}

public Cliente getCliente() {
	return cliente;
}

public void setCliente(Cliente cliente) {
	this.cliente = cliente;
}

public SelectItem getItemSelecionado() {
	return itemSelecionado;
}

public void setItemSelecionado(SelectItem itemSelecionado) {
	this.itemSelecionado = itemSelecionado;
}

public List<SelectItem> getTpPessoa() {
	return tpPessoa;
}

public void setTpPessoa(List<SelectItem> tpPessoa) {
	this.tpPessoa = tpPessoa;
}

public String getMascaraCpfCnpj() {
	return mascaraCpfCnpj;
}

public void setMascaraCpfCnpj(String mascaraCpfCnpj) {
	this.mascaraCpfCnpj = mascaraCpfCnpj;
}

}
[/code][/quote]

Gabriel, reveja o seu código, faça como o que eu te passei, tenho certeza absoluta que ele funciona!
Faz ele funcionar primeiro com o combo que eu passei
Estive vendo seu código e percebi que vc adaptou ele totalmente trocado…
Estou sem tempo de corrigir ele pra vc, então reveja com atenção que funciona sim!

Bom dia a todos, eu resolvi o meu problema a um tempinho atrás estou vindo postar a solução. Segui a ajuda da andii com relação de como utilizar o ajax e ficou tudo certinho e com relação ao rendered do meu form quando o usuário selecionar um dos radios o segredo era o seguinte, eu não posso tentar dar um render no meu componente que já possui na tag a propriedade rendered, tenho que criar um novo p:outputPanael no meu caso com um id e mandar renderizar ele. Li isto no blog do Rafael Pontes (http://www.rponte.com.br/), fica a dica! :smiley:
Aproveito este tbm para relatar outro problema que estou tendo, que é o seguinte: quando clico no botão gravar os meus beans não estão sendo populados com os valores preenchidos pelo usuário no form! Alguém sabe me dizer o que pode ser?

Segue a solução:

<ui:composition template="/paginas/principal.xhtml"> <ui:define name="conteudo"> <p:tabView> <!-- INÍCIO DA TAB DE CADASTRO --> <p:tab title="Cadastro" id="tabCadastroCliente"> <h:form prependId="false"> <h:panelGrid columns="2" cellspacing="1"> <h:selectOneRadio id="tipoPessoa" immediate="true" valueChangeListener="#{pessoaBean.trocarMascara}" > <f:selectItems value="#{pessoaBean.tpPessoa}" /> <f:ajax event="change" render="escondeForm" /> </h:selectOneRadio> </h:panelGrid> <p:outputPanel id="escondeForm"> <p:outputPanel id="formCadastroPessoa" rendered="#{pessoaBean.itemSelecionado.getValue() != null}"> <p:messages id="menssagens" showDetail="true"/> <p:ajaxStatus style="width:16px;height:16px;"> <f:facet name="start"> <h:graphicImage value="imagens/loading.gif" /> </f:facet> <f:facet name="complete"> <h:outputText value="" /> </f:facet> </p:ajaxStatus> <h:panelGrid columns="5" cellpadding="2" > <h:outputLabel id="labelCliNome" value="Nome: *"/> <h:outputLabel id="labelCpfCnpj" value="CPF/CNPJ: *"/> <h:outputLabel id="labelCliTel" value="Telefone: *"/> <h:outputLabel id="labelCliCel" value="Celular: *"/> <h:outputLabel id="labelDtNasc" value="Data Nasc.: "/> <p:inputText id="pesNome" maxlength="50" size="35" value="#{pessoaBean.pessoa.nome}" required="true" /> <p:inputMask mask="#{pessoaBean.mascaraCpfCnpj}" id="pesCpfCnpj" size="20" value="#{pessoaBean.cpfcnpj}" required="true"/> <p:inputMask mask="(99)9999-9999" id="pesTel" size="10" value="#{pessoaBean.tel}"/> <p:inputMask mask="(99)9999-9999" id="pesCel" size="10" value="#{pessoaBean.cel}" required="#{pessoaBean.validaTelefones()}"/> <p:calendar id="cliDtNasc" pattern="dd/MM/yyyy" mode="popup" value="#{clienteBean.cliente.dtNascimento}"/> </h:panelGrid> <h:panelGrid columns="5" cellpadding="2"> <h:outputLabel id="labelLogradouro" value="Logradouro: *"/> <h:outputLabel id="labelNrLogradouro" value="Nro: *"/> <h:outputLabel id="labelCep" value="CEP: *"/> <h:outputLabel id="labelBairro" value="Bairro: *"/> <h:outputLabel id="labelCidade" value="Cidade: *"/> <p:inputText id="pesLogradouro" required="true" maxlength="50" size="35" value="#{pessoaBean.pessoa.logradouro}"/> <p:inputText id="pesNrLogradouro" required="true" maxlength="6" size="5" value="#{pessoaBean.pessoa.nrLogradouro}"/> <p:inputMask mask="99.999-999" id="pesCep" required="true" size="10" value="#{pessoaBean.cep}" /> <p:inputText id="pesBairro" required="true" maxlength="35" size="25" value="#{pessoaBean.pessoa.bairro}"/> <p:inputText id="pesCidade" required="true" maxlength="35" size="25" value="#{pessoaBean.pessoa.cidade}" /> </h:panelGrid> <h:panelGrid columns="5" cellpadding="2"> <h:outputLabel id="labelEstado" value="Estado: *"/> <h:outputLabel id="labelIE" value="Insc. Estadual: *"/> <h:outputLabel id="labelContato" value="Contato: "/> <h:outputLabel id="labelCompra" value="Contato Compra: "/> <h:outputLabel id="labelPrincipal" value="Contato Principal: "/> <h:selectOneMenu id="pesEstado" required="true" immediate="true" value="#{pessoaBean.pessoa.estado}" valueChangeListener="#{clienteBean.aposEstadoSelecionado}"> <f:selectItems value="#{pessoaBean.estados}" /> <f:ajax event="change" render="cliIE"/> </h:selectOneMenu> <p:inputMask mask="#{clienteBean.mascaraIE}" id="cliIE" required="true" size="22" value="#{clienteBean.cliente.ie}"/> <p:inputText id="cliContato" maxlength="" size="" value="#{clienteBean.cliente.contato}"/> <p:inputText id="cliCompra" maxlength="" size="" value="#{clienteBean.cliente.contatoCompra}"/> <p:inputText id="cliPrincipal" maxlength="" size="" value="#{clienteBean.cliente.contatoPrincipal}"/> </h:panelGrid> <h:panelGrid columns="3" cellpadding="2"> <h:outputLabel id="labelPesEmail" value="E-Mail: "/> <h:outputLabel id="labelEmailCompra" value="E-Mail Compra: *"/> <h:outputLabel id="labelEmailPrincipal" value="E-Mail Principal: *"/> <p:inputText id="pesEmail" maxlength="80" size="35" value="#{pessoaBean.pessoa.email}"/> <p:inputText id="cliEmailCompra" maxlength="80" size="35" value="#{clienteBean.cliente.emailCompra}"/> <p:inputText id="cliEmailPrincipal" maxlength="80" size="35" value="#{clienteBean.cliente.emailPrincipal}"/> </h:panelGrid> </p:outputPanel> <p:commandButton id="btCadastrar" value="Gravar" actionListener="#{clienteBean.gravar}" /> </p:outputPanel> </h:form> </p:tab> </p:tabView> </ui:define> </ui:composition>

PessoaMB.java

[code]@ManagedBean(name=“pessoaBean”)
@RequestScoped
public class PessoaMB {

private Pessoa pessoa;
private SelectItem itemSelecionado;
private List<SelectItem> tpPessoa;
private String mascaraCpfCnpj;
private List<SelectItem> estados;
//variáveis para receber os valores com máscara
private String cpfcnpj;
private String tel;
private String cel;
private String cep;


public PessoaMB(){
	pessoa = new Pessoa();
	itemSelecionado = new SelectItem();
	tpPessoa = new ArrayList<SelectItem>();
	tpPessoa.add(new SelectItem("PF", "Pessoa Física"));
	tpPessoa.add(new SelectItem("PJ", "Pessoa Jurídica"));
	estados = new ArrayList<SelectItem>();
	estados.add(new SelectItem("Selecione", "Selecione"));
	estados.add(new SelectItem("AC", "Acre - AC"));
	estados.add(new SelectItem("AL", "Alagoas - AL"));
	estados.add(new SelectItem("AP", "Amapá - AP"));
	estados.add(new SelectItem("AM", "Amazonas - AM"));
	estados.add(new SelectItem("BA", "Bahia - BA"));
	estados.add(new SelectItem("CE", "Ceará - CE"));
	estados.add(new SelectItem("DF", "Distrito Federal - DF"));
	estados.add(new SelectItem("ES", "Espirito Santo - ES"));
	estados.add(new SelectItem("GO", "Goias - GO"));
	estados.add(new SelectItem("MA", "Maranão - MA"));
	estados.add(new SelectItem("MS", "Mato Grosso do Sul - MS"));
	estados.add(new SelectItem("MG", "Minas Gerais - MG"));
	estados.add(new SelectItem("PA", "Pará - PA"));
	estados.add(new SelectItem("PB", "Paraíba - PB"));
	estados.add(new SelectItem("PR", "Paraná - PR"));
	estados.add(new SelectItem("PE", "Pernambuco - PE"));
	estados.add(new SelectItem("PI", "Piauí - PI"));
	estados.add(new SelectItem("RJ", "Rio de Janeiro - RJ"));
	estados.add(new SelectItem("RN", "Rio Grande do Norte - RN"));
	estados.add(new SelectItem("RS", "Rio Grande do Sul - RS"));
	estados.add(new SelectItem("RO", "Rondônia - RO"));
	estados.add(new SelectItem("RR", "Roraima - RR"));
	estados.add(new SelectItem("SC", "Santa Cataria - SC"));
	estados.add(new SelectItem("SP", "São Paulo - SP"));
	estados.add(new SelectItem("SE", "Sergipe - SE"));
	estados.add(new SelectItem("TO", "Tocantins - TO"));
}

public void trocarMascara(ValueChangeEvent evt){
	itemSelecionado.setValue(evt.getNewValue());
	if(itemSelecionado.getValue() != null){
		String tipo = itemSelecionado.getValue().toString();
		if (tipo.equals("PJ")) {  
	        mascaraCpfCnpj = "99.999.999/9999-99";  
	    } else {  
	        mascaraCpfCnpj = "999.999.999-99";  
	    }  
	} 
}		

public boolean validaTelefones(){
	if(pessoa.getTelefone() == null && pessoa.getCelular() == null)
		return true;
	return false;
}

//getters and setters[/code]

[code]
@ManagedBean(name=“clienteBean”)
@SessionScoped
public class ClienteMB {

private PessoaMB pessoaMB;
private Cliente cliente;
private String mascaraIE;
private SelectItem itemSelecionado;
private String ie;
	
public void aposEstadoSelecionado(ValueChangeEvent evt){
	cliente = new Cliente();
	itemSelecionado.setValue(evt.getNewValue());
	String labelVlrSelecioado = itemSelecionado.getLabel().toString();
	if (labelVlrSelecioado.equalsIgnoreCase("AC"))
		this.setMascaraIE("99.999.999/999-99");
	else if(labelVlrSelecioado.equalsIgnoreCase("AL") || labelVlrSelecioado.equalsIgnoreCase("AP") || labelVlrSelecioado.equalsIgnoreCase("ES") || 
			labelVlrSelecioado.equalsIgnoreCase("MA")	|| labelVlrSelecioado.equalsIgnoreCase("MS") || labelVlrSelecioado.equalsIgnoreCase("PI") || 
			labelVlrSelecioado.equalsIgnoreCase("TO"))
		this.setMascaraIE("999999999");
	else if(labelVlrSelecioado.equalsIgnoreCase("AM") || labelVlrSelecioado.equalsIgnoreCase("GO") || labelVlrSelecioado.equalsIgnoreCase("RN"))
		this.setMascaraIE("99.999.999-9");
	else if(labelVlrSelecioado.equalsIgnoreCase("BA"))
		this.setMascaraIE("999999-99");
	else if(labelVlrSelecioado.equalsIgnoreCase("CE") || labelVlrSelecioado.equalsIgnoreCase("PB") || labelVlrSelecioado.equalsIgnoreCase("RR") || 
			labelVlrSelecioado.equalsIgnoreCase("SE"))
		this.setMascaraIE("99999999-9");
	else if(labelVlrSelecioado.equalsIgnoreCase("DF"))
		this.setMascaraIE("99999999999-99");
	else if(labelVlrSelecioado.equalsIgnoreCase("MG"))
		this.setMascaraIE("999.999.999/9999");
	else if(labelVlrSelecioado.equalsIgnoreCase("PA"))
		this.setMascaraIE("99-999999-9");
	else if(labelVlrSelecioado.equalsIgnoreCase("PR"))
		this.setMascaraIE("99999999-99");
	else if(labelVlrSelecioado.equalsIgnoreCase("PE"))
		this.setMascaraIE("99.9.999.9999999-9");
	else if(labelVlrSelecioado.equalsIgnoreCase("Rj"))
		this.setMascaraIE("99.999.99-9");
	else if(labelVlrSelecioado.equalsIgnoreCase("RS"))
		this.setMascaraIE("999/9999999");
	else if(labelVlrSelecioado.equalsIgnoreCase("RO"))
		this.setMascaraIE("999.99999-9");
	else if(labelVlrSelecioado.equalsIgnoreCase("RO"))
		this.setMascaraIE("999.999.999");
	else if(labelVlrSelecioado.equalsIgnoreCase("SP"))
		this.setMascaraIE("999.999.999.999");
}	

public void gravar(){
	setValoresSemMascara();
	cliente.setPessoa(pessoaMB.getPessoa());
	Session session = FacesContextUtil.getRequestSession();
	HibernateDAO<Cliente> dao = new HibernateDAO<Cliente>(Cliente.class, session);
	try {
		dao.salvar(getCliente());
	} catch (Exception e) {
		System.out.println("Erro ao tentar gravar!");
		e.printStackTrace();
	}
}

public void setValoresSemMascara(){
	pessoaMB.getPessoa().setCpfCnpj(Long.parseLong(removeMascaras(pessoaMB.getCpfcnpj())));
	pessoaMB.getPessoa().setTelefone(Long.parseLong(removeMascaras(pessoaMB.getTel())));
	pessoaMB.getPessoa().setCelular(Long.parseLong(removeMascaras(pessoaMB.getCel())));
	pessoaMB.getPessoa().setCep(Long.parseLong(removeMascaras(pessoaMB.getCep())));
}

public String removeMascaras(String s){
	String semMascara = s.replaceAll("[^\\p{ASCII}]", "");
	return semMascara;
}

//getters and setters[/code]

Desde já agradeço pela ajuda e atenção!