In my JSF view I have a p:selectCheckboxMenu
where I want to perform some business logic via AJAX on the selected values.
For a simple change
event it works fine, but for a toggleSelect
event not. Inside my listener method I am retrieving the old selection, but I am expecting the new selection here.
See the following example:
@ViewScoped
@Named
public class RequestBean implements Serializable {
private List<String> list; // + getter/setter
@PostConstruct
private void init() {
list = new ArrayList<String>() {{
add("one"); add("two"); add("three");
}};
}
public void listener() {
System.out.println("Current content of \"list\":");
for(String s : list) {
System.out.println(s);
}
}
}
in JSF view:
<p:selectCheckboxMenu value="#{requestBean.list}" label="List">
<f:selectItem itemValue="one" itemLabel="one"/>
<f:selectItem itemValue="two" itemLabel="two"/>
<f:selectItem itemValue="three" itemLabel="three"/>
<p:ajax event="toggleSelect" listener="#{requestBean.listener}" />
<p:ajax event="change" listener="#{requestBean.listener}" />
</p:selectCheckboxMenu>
Now lets consider the following use-case: You are entering the view, "one" and "two" are selected. If I click the "select all" checkbox, the outcome is:
Info: Current content of "list":
Info: one
Info: two
But the expected outcome would look like this:
Info: Current content of "list":
Info: one
Info: two
Info: three
For the regular change event it works as expected. Here I am getting the new selection inside the listener. How may I fix it? Or what am I doing wrong?
GlassFish 4.1, running on Java 1.8.0_45
JSF 2.2.10 (Mojarra)
PrimeFaces 5.1
OmniFaces 1.8.1