Subodh Subodh -4 years ago 95
Ajax Question

selectOneMenu not populating another selectOneMenu using ajax listener

I am using two selectOneMenu. Selection of first one should populates the second one by providing the selected value as a parameter. I have gone through a lot of online stuff but still not find a way to resolve it. The listener method is getting called on dropdown value change. Someone please help me out. (it works only if i enable the commented line)

<p:selectOneMenu value="#{myBean.mGroup}" id="mGroup" style="width:130px;" >
<f:selectItem itemLabel="Environment" itemValue="E"></f:selectItem>
<f:selectItem itemLabel="Health" itemValue="H"></f:selectItem>
<f:selectItem itemLabel="Physical" itemValue="P"></f:selectItem>
<p:ajax render="@form" listener="#{myBean.mGroupChangedListener}" />

<p:selectOneMenu id="mClass" style="width: 130px;" value="#{myBean.mClass}">
<!-- <f:selectItem itemLabel="Temp1" itemValue="Temp1" /> if i remove comment from this line, it works -->
<f:selectItems value="#{myBean.mClassList}" var="clas" itemLabel="#{clas.mClassDesc}" itemValue="#{clas.mClassId}" />

// listener method
public void mGroupChangedListener(AjaxBehaviorEvent event) {
List<MClass> mClassList = service.getMClass(event.getComponent().getAttributes().get("value").toString());

Answer Source

Replace <p:ajax render="@form" with <p:ajax update="@form"

in primefaces (p:ajax) use:

update instead of render


process instead of execute

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download