Here is my checkbox. I am preparing a comma delimited string of component ids in the listener. The problem here is the getter getUpdateComponentList() is being called before the listener is called. So the string is never updated.
<p:outputPanel>
<h:selectManyCheckbox value="#{form.colors}">
<f:selectItems value="#{form.colorItems}"/>
<p:ajax listener="#{form.testListener}" event="change" update="#{form.updateComponentList}" />
</h:selectManyCheckbox>
</p:outputPanel>
That's expected behaviour. PrimeFaces (and standard JSF) does not re-evaluate the update (and render, oncomplete, etc) attributes on a per-request basis. They are evaluated on a per-view basis. RichFaces, for example, does it in its <a4j:ajax> and yields exactly the expected behaviour.
For PrimeFaces, your best bet is to remove the update attribute and use RequestContext#addPartialUpdateTarget() or #addPartialUpdateTargets() in the action method instead.
E.g.
RequestContext.getCurrentInstance().addPartialUpdateTargets(updateComponentList);
It takes a Collection<String> such as List<String> or Set<String>.
By the way, that event="change" is unnecessary. Just use the component's default event.
Update for users of a newer PrimeFaces version who are reading this answer later on and can't find the aforementioned methods which are indeed removed in a newer PrimeFaces version; use one of the two update() methods instead (one takes a String and other takes a Collection<String>).
RequestContext.getCurrentInstance().update(updateComponentList);
I faced a similar problem about 'update' getting executed before the 'listener'. Putting two 'p:ajax' -one with the listener and other with the update- did the trick.
In your case:
<p:outputPanel>
<h:selectManyCheckbox value="#{form.colors}">
<f:selectItems value="#{form.colorItems}"/>
<p:ajax event="change" listener="#{form.testListener}" />
<p:ajax event="change" update="#{form.updateComponentList}" />
</h:selectManyCheckbox>
</p:outputPanel>
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With