How to render a jsf component through Bean?

0

I need to render a jsf component (Primefaces) through the Bean. I have a selectOneMenu that changes the type of person (physical / legal) and I need to render the field "CPF", since I use the same field for CPF / CNPJ and when changing the type, I need to change the input mask. >

How to do it?

    
asked by anonymous 06.11.2015 / 23:17

1 answer

2

<p:outputLabel class="required" value="Tipo de Pessoa:" for="tipo" />
<h:panelGroup>
  <p:selectOneRadio id="tipo" value="#{cadastroClienteBean.cliente.tipo}">
    <f:selectItems value="#{cadastroClienteBean.tiposPessoas}" var="tipoPessoa" itemValue="#{tipoPessoa}" itemLabel="#{tipoPessoa.descricao}" />
    <p:ajax event="change" update="grupoLabel, grupoInput" process="@this" />
  </p:selectOneRadio>
</h:panelGroup>

<h:panelGroup id="grupoLabel">
  <p:outputLabel class="required" value="CPF:" for="cpf" rendered="#{cadastroClienteBean.cliente.tipo eq 'FISICA'}" />
  <p:outputLabel class="required" value="CNPJ:" for="cnpj" rendered="#{cadastroClienteBean.cliente.tipo eq 'JURIDICA'}" />
</h:panelGroup>

<h:panelGroup id="grupoInput">
  <p:inputMask mask="999.999.999-99" value="#{cadastroClienteBean.cliente.documentoReceitaFederal}" id="cpf" rendered="#{cadastroClienteBean.cliente.tipo eq 'FISICA'}" style="width: 50%" />
  <p:inputMask mask="99.999.999/9999-99" value="#{cadastroClienteBean.cliente.documentoReceitaFederal}" id="cnpj" rendered="#{cadastroClienteBean.cliente.tipo eq 'JURIDICA'}" style="width: 60%" />
</h:panelGroup>

Old post more can help other people ... I use this way using ENUM ...

    
07.07.2016 / 01:15