I need your assistance in showing and hiding inputText
based on the selected items in the selectManyCheckbox
in 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.