How to render a jsf component through the bean?

Asked

Viewed 859 times

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", because I use the same field for CPF/CNPJ and when changing the type, I need to change the input mask.

How to do?

  • I’m gonna kick it here. <p:inputMask mask="#{meuBean.padrao}" />

  • Yes, this is the basics, but my problem would be to create a component in xhtml via java code (bean).

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>

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

Browser other questions tagged

You are not signed in. Login or sign up in order to post.