0
votes

I have created a component that has a delete button per row. When the delete button is clicked, a confirmDialog will be called and upon clicking 'Yes' on the dialog, the row will be deleted.

The table refreshes, but the wrong row is removed on the UI . On the bean, the correct record is deleted. On the UI side, the row removed is always the last row, no matter which row you pick to delete.

The Delete button is in the datatable itself and the confirmDialog is located outside the datatable but within the same form.

Does anybody know what is wrong?

<p:commandButton icon="ui-icon ui-icon-trash"
        update="@form"
        oncomplete="del_confirmation.show()"
        value="Delete" 
        immediate="true">
       <f:setPropertyActionListener value="#{item}" 
         target="#{Bean.recToDelete}"/>
</p:commandButton>


<p:confirmDialog widgetVar="del_confirmation"
message="Confirm Delete?"
header="Delete Dialog" showEffect="explode"
hideEffect="explode" modal="true">
<div align="center">
    <p:commandButton id="delBtn"
        icon="ui-icon ui-icon-check"
        value="Yes"
        actionListener="#{Bean.deleteRecord()}"
        update="@form"
        oncomplete="del_confirmation.hide()" 
        immediate="true"
        ajax="true" />
    <p:commandButton
        icon="ui-icon ui-icon-cancel" 
        value="No"
        onclick="del_confirmation.hide()" />
</div></p:confirmDialog>
1
try to narrow the use case, double check that every row item has a unique id, make sure that the relevant id is being deleted, and after that double check that its being removed from the list of items... use system.out....Daniel
Hi Daniel, thanks for your suggestion. However, because I have verified that in the backend bean it works, I suspect it is more related to caching or similar aspects of the datatable. Is this thought valid?Esther Goh
show your datatable code only the p:datatable... there is no caching in the table, also try removing the immediate and replace the f:setPropertyActionListener by using action="#{myBean.myDeleteMethod(item)}"Daniel
Yes that worked, by removing the immediate = true. Thanks!Esther Goh

1 Answers

1
votes

Show your datatable code, only the p:datatable...

There is no caching in the table, also try removing the immediate and replace the f:setPropertyActionListener by using action="#{myBean.myDeleteMethod(item)}"