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(andrender,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
updateattribute and useRequestContext#addPartialUpdateTarget()or#addPartialUpdateTargets()in the action method instead.E.g.
It takes a
Collection<String>such asList<String>orSet<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 aStringand other takes aCollection<String>).