Conditionally rendering <f:selectItem> inside <c:if>,<ui:fragment>
Problem Description:
I need to display No Jurisdiction to add in the Jurisdiction dropdown when the given condition satisfies.[condition:When there is no Jurisdiction available,it should display the above text in dropdown.If there are jurisdictions available,the above text should not be displayed].And I dont want to make it disabled.
The problem i am facing is whether it does or does not displays No Jurisdiction to add irrespective of the condition provided.
<p:selectOneMenu id="JurisdictionName"
value="#{ApplicationManagedBean62.saveRequestMap['Jurisdiction']}"
<f:selectItem itemLabel="Select" itemValue="" />
<c:if test="#{empty ApplicationManagedBean62.knowledgeValueMap['Object::AddJurisdictionStatelist']}">
<f:selectItem itemLabel="No Jurisdiction to add" itemValue="" />
</c:if>
<f:selectItems
value="#{ApplicationManagedBean62.knowledgeValueMap['Object::AddJurisdictionStatelist']}"
var="Jurisdiction"
itemLabel="#{Jurisdiction['StateRegionCode']}"
itemValue="#{Jurisdiction['StateRegionCode']}" />
</p:selectOneMenu>
I also tried,
<ui:fragment rendered="#{empty ApplicationManagedBean62.knowledgeValueMap['Object::AddJurisdictionStatelist']}">
<f:selectItem itemLabel="No Jurisdiction to add" itemValue="No Jurisdiction to add" />
</ui:fragment>
Kindly help me out.
Solution – 1
You can’t do it like that you have 2 choices.
Use
itemDisabled="true"
ornoSelectionOption="true"
on items you don’t want selectable and they will be greyed out. See: https://javaee.github.io/glassfish/doc/5.0/vdldoc/f/selectItem.htmlGenerate your selectItems server side and filter out the ones you know should not be there like this…
<f:selectItems value="#{myBean.jurisdictions}" var="type" itemLabel="#{type.displayText}" itemValue="#{type}" />