Update JSF only works in the whole form (Primefaces)

Asked

Viewed 699 times

0

good night. I’m racking my brain with a problem that seemed simple

I have a form with some fields, when selecting a combobox I want to hide and display some fields. I am using p:ajax to perform the update.

And in the fields to hide, I’m using' rendered'.

Everything works perfectly if I execute the command:

<p:ajax update="frmCad" event="change" />

This practice is not legal because it always resets all other fields that will already be filled. However, if I set the specific field to update, it does nothing. In this case it would be:

<p:ajax update="pam:lblSexo" event="change" />

Someone could give me a light?

In short, my code is as follows::

<h:form id="frmCad" prependId="false">
  <p:accordionPanel id="pam" multiple="true" activeIndex="0,1">
    <p:tab id="tbCad" title="Cadastro" >
      <h:panelGrid id="gp1" columns="3" columnClasses="primeiraColumnP">

      <h:outputLabel id="lblSegPessoa" for="id" value="Pessoa: " styleClass="estilolabelCampos" />
      <p:selectOneRadio id="optTipo" value="#{pessoaBeanView.objetoSelecionado.pes_tipo_pessoa}">
        <f:selectItem itemLabel="Física" itemValue="Fisica" />
        <f:selectItem itemLabel="Jurídica" itemValue="Juridica" />
        <p:ajax update="pam:lblSexo" event="change" />
      </p:selectOneRadio>

  <p:outputLabel id="lblSexo" value="Sexo: " rendered="#{pessoaBeanView.objetoSelecionado.pes_tipo_pessoa == 'Fisica'}" />

...fechamentos>

I appreciate the help.

  • Is your bean Viewscoped? I believe it is from Request, so the other fields are reset.

1 answer

0


The update will only work if the component lblSexo is rendered. Try making the following change:

(...)

<p:ajax update="pnlSexo" event="change" />

(...)

<h:panelGroup id="pnlSexo">
    <p:outputLabel id="lblSexo" value="Sexo: " rendered="#{pessoaBeanView.objetoSelecionado.pes_tipo_pessoa == 'Fisica'}" />
</h:panelGroup>
  • That’s right, The object can only be displayed if it is rendered on startup. As the panel had been, it normally loaded. Thank you very much for your help.

Browser other questions tagged

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