1

I am unable to rendered a selectOneMenu but only to disable the item

for example this is working:

<p:panel header="Field Chooser">  
    <h:panelGrid columns="2" cellpadding="5">  
        <p:selectOneMenu id="l1" value="#{acqBean.gb1}">  
            <f:selectItem itemLabel="Group By" itemValue="" />  
            <f:selectItems value="#{acqBean.level1}" />  
            <p:ajax update="l2" listener="#{acqBean.handleGroupChange}"/>  
        </p:selectOneMenu>  
        <p:selectOneMenu id="l2" value="#{acqBean.gb2}" disabled="#{acqBean.renderLevel2}">  
            <f:selectItems value="#{acqBean.level2}" />  
        </p:selectOneMenu>  
    </h:panelGrid>  
    <p:separator /> 
</p:panel> 


public void handleGroupChange() {
    if (gb1 != null && !gb1.equals("")) {
        level2 = level2Data.get(gb1);
        renderLevel2 = false;
    } else {
        level2 = new HashMap<String, String>();
        renderLevel2 = true;
    }
}

and this one not:

<p:selectOneMenu id="l2" value="#{acqBean.gb2}" rendered="#{acqBean.renderLevel2}">  
            <f:selectItems value="#{acqBean.level2}" />  
        </p:selectOneMenu> 

Any advice please

Thanks

angus
  • 3,210
  • 10
  • 41
  • 71

1 Answers1

3

You can't ajax-update a component which is by itself conditionally rendered. You can only ajax-update a component which is always rendered. The simple reason is, when the component is not rendered, then there's basically nothing in the resulting HTML code which can be selected and manipulated by JavaScript based on the ajax response.

So, put the <p:selectOneMenu> with the rendered attribute in for example a <h:panelGroup> without the rendered attribute and refer it instead in your ajax update.

<p:selectOneMenu id="l1" value="#{acqBean.gb1}">  
    <f:selectItem itemLabel="Group By" itemValue="" />  
    <f:selectItems value="#{acqBean.level1}" />  
    <p:ajax update="l2group" listener="#{acqBean.handleGroupChange}"/>  
</p:selectOneMenu>  
<h:panelGroup id="l2group">
    <p:selectOneMenu id="l2" value="#{acqBean.gb2}" rendered="#{acqBean.renderLevel2}">  
        <f:selectItems value="#{acqBean.level2}" />  
    </p:selectOneMenu>  
</h:panelGroup>

See also:

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