JSF(Primefaces) ajax update of several elements by ID's
One more question concerning JSF.Particularly, Primefaces.
Have following problem with ajax update of elements by id's at same time. If elements on page goes one by one ,that ajax update performs ok:
<ui:repeat value="#{showProducts.inCart}" var="cart">
<td><p:spinner min="0" value="#{cart.count}" immediate="true">
<p:ajax process="@this" update="count,subTotal"/></p:spinner></td>
<td><h:outputText value="#{cart.totalPrice}" id="count"/></td>
<h:outputText value="#{showProducts.subTotal}" id="subTotal"/>
</ui:repeat>
Here element with id "count" goes first,then element with id "subtotal" goes second. In case,elements on page are not strictly one by one,that second element with "subtotal" id is not updated:
<ui:repeat value="#{showProducts.inCart}" var="cart">
<td><p:spinner min="0" value="#{cart.count}" immediate="true">
<p:ajax process="@this" update="count,subTotal"/></p:spinner></td>
<td><h:outputText value="#{cart.totalPrice}" id="count"/></td>
<td><h:outputText value="#{cart.place}" /></td>
</ui:repeat>
<h:outputText value="#{showProducts.subTotal}" id="subTotal"/>
Is it normal behaviour or I miss some parameters?
If the to-be-updated component is not inside the same NamingContainer
component ( ui:repeat
, h:form
, h:dataTable
, etc), then you need to specify the "absolute" client ID. Prefix with :
(the default NamingContainer
separator character) to start from root.
<p:ajax process="@this" update="count :subTotal"/>
To be sure, check the client ID of the subTotal
component in the generated HTML for the actual value. If it's inside for example a h:form
as well, then it's prefixed with its client ID as well and you would need to fix it accordingly.
<p:ajax process="@this" update="count :formId:subTotal"/>
Space separation of IDs is more recommended as <f:ajax>
doesn't support comma separation and starters would otherwise get confused.