Hide fields on form using Primefaces

0

I have a problem, I am making a form in primefaces and the following happens to me:

View code xhtml

<p:panel>

   <p:selectOneRadio layout="responsive" columns="2" value="#{empresaWizard.empresa.stAceptoMultiswitch}">
    <f:selectItem itemLabel="Si" itemValue="1" />
    <f:selectItem itemLabel="No" itemValue="0" />
  </p:selectOneRadio>

  <p:inputText  required="true" value="#{empresaWizard.empresa.nbComercial}"  label="Nombre de la Empresa" placeholder="Nombre de la Empresa" size="50"  "/>
</p:panel>

I would like that when it's state is 1 my input is hidden but I can not do it, some contribution that can help me, I use rendered="# {empresaWizard.empresa.stAceptoMultiswitch} eq 1.Forward thanks

    
asked by Jasi Enriquez 09.09.2017 в 19:11
source

1 answer

0

You need to evaluate the rendered condition of the input each time the value of selectOneRadio changes in value.

Since the condition of the check checks the value of empresaWizard.empresa.stAceptoMultiswitch , that is, the value of a member of your backing bean, you need to raise an ajax event when you change the value of the radio-button so that the bean has the adequate value.

Then, you need to re-evaluate the condition of rendered with the updated value.

To solve this you can use p: ajax and indicate which items to update at the end of the response using the update attribute

<p:panel>

   <p:selectOneRadio layout="responsive" columns="2" value="#{empresaWizard.empresa.stAceptoMultiswitch}">
    <f:selectItem itemLabel="Si" itemValue="1" />
    <f:selectItem itemLabel="No" itemValue="0" />
    <p:ajax update=":nombre-empresa" />    
  </p:selectOneRadio>

  <p:inputText  id="nombre-empresa" required="true" value="#{empresaWizard.empresa.nbComercial}" label="Nombre de la Empresa" placeholder="Nombre de la Empresa" size="50"  rendered="#{empresaWizard.empresa.stAceptoMultiswitch eq 1} "/>
</p:panel>

In turn, to evaluate if the option 1 was chosen you must place the operator equals (eq) inside the Expression Languaje (EL):

#{empresaWizard.empresa.stAceptoMultiswitch eq 1}
    
answered by 10.09.2017 в 05:48