jsf - Primefaces DataTable - deleting with dialog deletes wrong entry -
i have table in form. 1 of columns in table displays row of buttons edit , delete table entries. when delete entry callign controller button's action
attribute, works expected.
but once have added dialog let user confirm deletion, wrong entry deleted. last entry in current table. have no idea reason - using same datatable
var
button , dialog.
i working jsf 2 (mojarra 2.1.6) , primefaces 3.5 deploying on jboss 7.1.1 on suse 12.2 machine.
the form:
<h:form id="downloads"> <ui:include src="components/table.xhtml"/> </h:form>
the table:
<ui:composition> <p:datatable value="#{controller.currentlevelresources}" var="download" id="downloadtable" scrollheight="120" rows="10"> <p:column sortby="#{download.name}"> <f:facet name="header">name</f:facet> <h:outputtext id="downloadname" value="#{download.name}" title="#{download.description}" /> </p:column> ... <p:column> <ui:include src="menubar.xhtml"></ui:include> </p:column>
the menu bar:
<ui:composition> <p:commandbutton id="edit" action="#{downloadeditcontroller.editresource(download)}" icon="ui-icon-gear" title="edit" oncomplete="updatestyles()" update=":downloads" /> <p:commandbutton id="delete" onclick="deleteddlg.show();" icon="ui-icon-trash" title="delete" oncomplete="updatestyles()" /> <p:dialog header="delete confirmation" widgetvar="deleteddlg" resizable="false"> <h:panelgroup layout="block" style="padding:5px;"> <h:outputtext value="the resource #{download} deleted. proceed?" /> </h:panelgroup> <p:commandbutton id="deletebtn" value="delete" oncomplete="deleteddlg.hide(); updatestyles(); " action="#{downloadeditcontroller.deleteresource(download)}" process="@this" update=":downloads"> </p:commandbutton> <p:commandbutton value="cancel" type="button" onclick="deleteddlg.hide();" /> </p:dialog>
if replace dialog this, works:
<p:commandbutton id="delete" icon="ui-icon-trash" title="delete" action="#{downloadeditcontroller.deleteresource(download)}" oncomplete="updatestyles()" update=":downloads" />
creating <p:dialog>
every row not idea.
for starters had better create single <p:dialog>
outside <p:datatable>
.
next thing set id or row var in bean upon delete button click , in case of confirmation in dialog use id or row var bean delete.
this how delete button like, set download
var in preparedatafordeletion
action , show dialog...
<p:commandbutton id="deleteconfirmation" icon="ui-icon-trash" title="delete" action="#{downloadeditcontroller.preparedatafordeletion(download)}" onsucess="deleteddlg.show();"/>
regarding current anomaly: it's because dialogs have same widgetvar
, each next 1 overriding declared 1 way until last one. dynamically give them different widget names widgetvar="deletedlg_#{someindex}"
, makes no sense if can have 1 reusable dialog content updated before opening.
Comments
Post a Comment