I would like to call an action from a backing bean immediately after a value in a PF selectOneMenu is selected without using any button or link. I already looked at this question:
When to use valueChangeListener or f:ajax listener?
While very useful, I am not able to apply the recommended business logic that would allow the action to be called dynamically based on ONLY the selected value from the menu. I know how to use ajax to render changed values between two menus (where the value of one menu is changed). The options discussed on the above questions do not seem to work in my case which leads me to look deeper into the EL and backing bean methods to understand these concepts better.
I tried two ways to allow dynamic processing of my menu paramteres. The first was to use the valueChangeListener ayttribute in the EL:
<p:selectOneMenu id="Ctl" value="#{actionBean.department}"
valueChangeListener="#{actionBean.ShowListDeptAct(event)}" onchange="submit()">
<f:selectItem itemLabel="Dept A" itemValue="Dept A"/>
<f:selectItem itemLabel="Dept B" itemValue="Debt B"/>
<f:selectItem itemLabel="Dept C" itemValue="Dept C"/>
</p:selectOneMenu>
The bean method:
public void ShowListDeptAct(ValueChangeEvent event) {
department = FacesContext.getCurrentInstance().getExternalContext().getRequestParameterMap().get("department");
listDeptActions();
}
public String listDeptActions() {
//department = getDepartment();
deptActions = facade.findByDept(department);
return "DeptAction";
This only results in refreshing the page and the bean method does not even to be functioning.
The second way was to use the p ajax tag:
<p:selectOneMenu id="Ctl" value="#{actionBean.department}">
<a href="ActionMaster.xhtml"></a>
<f:selectItem itemLabel="Dept A" itemValue="Dept A"/>
<f:selectItem itemLabel="Dept B" itemValue="Debt B"/>
<f:selectItem itemLabel="Dept C" itemValue="Dept C"/>
<p:ajax listener="#{actionBean.ShowListDeptAct}" oncomplete="submit()"/>
</p:selectOneMenu>
bean method:
public void ShowListDeptAct(AjaxBehaviorEvent event) {
department = FacesContext.getCurrentInstance().getExternalContext().getRequestParameterMap().get("department");
listDeptActions();
}
public String listDeptActions() {
//department = getDepartment();
deptActions = facade.findByDept(department);
return "DeptAction";
}
This resulted in exactly the same behavior which makes me think my problem might be a mistake in how I"m writing the listener.
The EL is supposed to pass the name of the selected department to the following backing bean methods which will display a dataTable of the data for the selected department. The backing bean methods:
After reading the PF User Guide and some questions here, I'm neither sure about how to pass the correct EL nor the right backing bean methods to achieve this. Would appreciate some guidance. Thank you!