Conditionally rendering <f:selectItem> inside <c:if>,<ui:fragment>

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.

enter image description here

The problem i am facing is whether it does or does not displays No Jurisdiction to add irrespective of the condition provided.

enter image description here

<p:selectOneMenu id="JurisdictionName"
 <f:selectItem itemLabel="Select" itemValue="" />
    <c:if test="#{empty ApplicationManagedBean62.knowledgeValueMap['Object::AddJurisdictionStatelist']}">
        <f:selectItem itemLabel="No Jurisdiction to add" itemValue=""  />
        itemValue="#{Jurisdiction['StateRegionCode']}" />

I also tried,

<ui:fragment rendered="#{empty ApplicationManagedBean62.knowledgeValueMap['Object::AddJurisdictionStatelist']}">
    <f:selectItem itemLabel="No Jurisdiction to add" itemValue="No Jurisdiction to add"  />

Kindly help me out.

Solution – 1

You can’t do it like that you have 2 choices.

  1. Use itemDisabled="true" or noSelectionOption="true" on items you don’t want selectable and they will be greyed out. See:

  2. Generate 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}" />
Rate this post
We use cookies in order to give you the best possible experience on our website. By continuing to use this site, you agree to our use of cookies.