2

I want to disable some primefaces components after a selection from p:selectOneMenu but when I choose no selection option it still disabled

<p:outputLabel value="Manager" style="color:white;font-weight: bold;" />
<p:selectOneMenu id="manager" value="#{employeeMB.selectedManager}" immediate="true">
     <f:selectItem itemLabel="Selectionner..." noSelectionOption="true"/>
     <f:selectItems value="#{employeeMB.managers}"  />
     <p:ajax update="managerSelect role"  />
</p:selectOneMenu>

<p:outputLabel value="Est un Manager" 
               style="color:white;font-weight: bold;" />
<p:selectBooleanCheckbox id="managerSelect" 
                         value="#{employeeMB.employee.isManager}" 
                         disabled="#{employeeMB.selectedManager != null}" />

<p:outputLabel for="role" value="Role Utilisateur" style="color:white;font-weight: bold;" />
<p:selectManyCheckbox id="role" value="#{employeeMB.selectedRoles}">
    <f:selectItem itemLabel="Employée" itemValue="ROLE_EMPLOYEE" />
    <f:selectItem itemLabel="Manager" itemValue="ROLE_MANAGER" itemDisabled="#{employeeMB.selectedManager != null}"/>
    <f:selectItem itemLabel="RH" itemValue="ROLE_RH" itemDisabled="#{employeeMB.selectedManager != null}"/>
</p:selectManyCheckbox>
Spartan
  • 1,167
  • 4
  • 20
  • 40

1 Answers1

5

That can happen when the updated model value is not null, but an empty string. You'd need to reconfigure JSF to interpret empty string submitted values as null to avoid the model being polluted with empty strings via below entry in web.xml.

<context-param>
    <param-name>javax.faces.INTERPRET_EMPTY_STRING_SUBMITTED_VALUES_AS_NULL</param-name>
    <param-value>true</param-value>
</context-param>

Nonetheless, better use #{not empty bean.property} instead of #{bean.property != null}. It also covers empty strings.


Unrelated to the concrete problem, the noSelectionOption is useless over there. Carefully read Best way to add a "nothing selected" option to a selectOneMenu in JSF to understand it. I also have my doubts about your understanding of the immediate attribute there. Get rid of it. It has no sensible value anymore in JSF 2.x world thanks to all that ajax magic.

Community
  • 1
  • 1
BalusC
  • 1,082,665
  • 372
  • 3,610
  • 3,555