0

I need your assistance in showing and hiding inputText based on the selected items in the selectManyCheckboxin the xhtml. The code is:

<p:selectManyCheckbox id="basic" value="#{user1.selectedConsoles}">
  <f:selectItem itemLabel="Xbox One SS" itemValue="XboxOne" />
  <f:selectItem itemLabel="PS4 SS" itemValue="PS4" />
  <f:selectItem itemLabel="Wii U SS" itemValue="WiiU" />
  <p:ajax listener="#{user1.renderInput}" update="name"/>
</p:selectManyCheckbox>

 <h:panelGroup id="name">
  <p:inputText value="" rendered="#{user1.renderText}"/>
 </h:panelGroup>

And the bean code:

private String[] selectedConsoles; //Setter & Getter
private List<String> list = new ArrayList<String>(); //Setter & Getter
private boolean renderText = false; //Setter & Getter


public void renderInput() {
  list= Arrays.asList(selectedConsoles);
  if (list.contains("PS4")) {
    renderText = true;
  }
  else if (!list.contains("PS4")) {
        renderText = false;
  }
}

If the selectManyCheckbox contains ("PS4"), then show the inputText, otherwise keep it hidden. Now in the above case, it is showing if I have selected PS4, but when I unckeck PS4, the inputText will remain in the form and will not be hidden.

99maas
  • 1,239
  • 12
  • 34
  • 59
  • @Kukeltje The first part is similar, however for the second part it is different – 99maas May 22 '15 at 13:51
  • Yes, but there should only be one question per question. So it still is a duplicate. file a new question for the second part. – Kukeltje May 22 '15 at 14:05

1 Answers1

1

Try this instead - the inputText is not visible at the start, so it cannot be updated.

 <h:panelGroup id="name">
      <p:inputText value="" rendered="#{user1.renderText}"/>
 </h:panelGroup>
Evan Knowles
  • 7,426
  • 2
  • 37
  • 71