0

I am using primefaces selectoneradio control which will show or hide the panelgrid after selection. But does not know why it cannot hide this panelgrid when selectl allTeachers radio.

public boolean getVisibleTeacherList() {
    if (this.selectedAllTeachersFlag == "AllTeachers")
        return false;
    else 
        return true;
}

<p:panelGrid columns="2">
    <p:selectOneRadio id="console" value="#{chkTeacherList.selectedAllTeachersFlag}">
        <f:selectItem itemLabel="All teachers" itemValue="AllTeachers" />
        <f:selectItem itemLabel="Selected teachers" itemValue="SelectedTeachers" />
        <p:ajax update="panelGrid1a1" />
    </p:selectOneRadio>
</p:panelGrid>
<p:panelGrid id="panelGrid1a1" rendered="#{chkTeacherList.getVisibleTeacherList()}" columns="1" styleClass="ui-edb-noneborder-grid">
    <p:separator style="border: 1px solid #8c4eea;" />
    <p:panelGrid id="panelGrid1"  columns="3" styleClass="ui-edb-noneborder-grid">
        <p:selectManyCheckbox layout="grid" id="gridTeacherName"  value="#{chkTeacherList.selectedValue}" 
                             columns="3">
            <f:selectItems value="#{chkTeacherList.filterTeacherNameList}" var="teacher" itemLabel="#{teacher.teacherEngName}" itemValue="#{teacher.timRefNo}" />
        </p:selectManyCheckbox>
    </p:panelGrid>
    <p:separator style="border: 1px solid #8c4eea;" />
</p:panelGrid>
Cœur
  • 37,241
  • 25
  • 195
  • 267

3 Answers3

0

The issue can be with your boolean getter getVisibleTeacherList. It should be isVisibleTeacherList for visibleTeacherList property.

More-ever, I think this separate property is not required. You can handle rendering of panelGrid using:

rendered="#{chkTeacherList.selectedAllTeachersFlag eq 'AllTeachers'}"
Parkash Kumar
  • 4,710
  • 3
  • 23
  • 39
0

To add or remove component (when it changes its rendered value) you need to update not the component itself, but one of its ancestor components.

E.g., say your panelGrid1a1 is located inside parentPanel.

<p:outputPanel id="parentPanel">
    <p:panelGrid id="panelGrid1a1" rendered="#{chkTeacherList.getVisibleTeacherList()}" ...
    ...
</p:outputPanel>

Then your p:selectOneRadio's p:ajax should update parentPanel.

<p:selectOneRadio id="console" ...
    ...
    <p:ajax update="parentPanel" />
</p:selectOneRadio>
Vsevolod Golovanov
  • 4,068
  • 3
  • 31
  • 65
0

A quick fix try replacing this:

this.selectedAllTeachersFlag == "AllTeachers"

with

this.selectedAllTeachersFlag.equals("AllTeachers")

Difference

  • "==" is a reference comparison, i.e. both objects point to the same memory location. where
  • "equals()" evaluates to the comparison of values in the objects.
Sarz
  • 1,970
  • 4
  • 23
  • 43