I have a column inside a <rich:dataTable> that contains <a4j:commandButton> for deleting rows.
Deleting rows works fine when calling bean’s delete function (e.g. #{bean.deleteCar(record.carId)}) via commandButton’s action attribute. Unfortunately, when using <a4j:jsFunction>‘s action attribute the record.carId of the last row is passed to the bean, instead of the selected row.
Some code for clarification. The following deletes the car of the clicked row:
<a4j:commandButton value="Delete"
action="#{bean.deleteCar(record.carId)}"/>
The following deletes last row’s car:
<a4j:commandButton value="Delete"
onclick="#{rich:component('confirmDeletePane')}.show()">
<a4j:jsFunction name="deleteCar"
action="#{bean.deleteCar(record.carId)}"
oncomplete="#{rich:component('confirmDeletePane')}.hide();"
render="carsTable"/>
</a4j:commandButton>
<rich:popupPanel id="confirmDeletePane" header="Delete" modal="true" autosized="true" onmaskclick="#{rich:component('confirmDeletePane')}.hide();">
<h:outputText value="Delete?"/>
<h:panelGroup>
<a4j:commandButton value="Cancel" onclick="#{rich:component('confirmDeletePane')}.hide(); return false;" />
<a4j:commandButton value="OK" onclick="deleteCar(); return false;"/>
</h:panelGroup>
</rich:popupPanel>
As you can see I’m trying to confirm user’s selection before deletion.
Thanks in advance.
As the showcase suggests, I concluded that a refined solution is to use indices for row selections. I’m copying here for future reference.
The commandLink (calls confirmPane):
The confirmPane (calls the JS function):
The jsFunction (calls Bean’s function):
In the backing bean: