I'm using Primefaces datatable and have a column containing delete button. And I'm facing similar problem like here : Primefaces Delete & Confirm Dialog inside table column - Update or Freeze
I tried the solution given there but it's not working. In my case the method vehiTypeListMngr.deletVehicleType
registered with actionListener
of <p:commandButton
is not getting invoked. Also #{vehiTypeListMngr.selectedVehiType.type}
is displayed null in the confirm dialog box. Any idea why it's not working?
<h:body> <h:form id="formListVehiType"> <p:dataTable id="vTypeTable" var="vType" value="#{vehiTypeListMngr.vehiTypes}" rowKey="#{vType.vehicleTypeId}" style="margin-bottom:20px" paginator="true" rows="10" paginatorTemplate="{RowsPerPageDropdown} {FirstPageLink} {PreviousPageLink} {CurrentPageReport} {NextPageLink} {LastPageLink}" currentPageReportTemplate="{startRecord}-{endRecord} of {totalRecords} records" rowsPerPageTemplate="5,10,15" selection="#{vehiTypeListMngr.selectedVehiType}" selectionMode="single"> <p:column headerText="VehicleTypeId" visible="none"> <h:outputText value="#{vType.vehicleTypeId}" /> </p:column> <p:column headerText="Vehicle Type" style="width:120px;"> <h:outputText value="#{vType.type}" /> </p:column> <p:column headerText="Delete" style="width:45px; text-align: center;"> <p:commandButton value="" icon="ui-icon-delete" type="button" styleClass="ui-confirmdialog-yes" oncomplete="PF('deleteDlg').show();" update=":formListVehiType:display"> <f:setPropertyActionListener value="#{vType}" target="#{vehiTypeListMngr.selectedVehiType}" /> </p:commandButton> </p:column> </p:dataTable> <p:dialog id="confirmDeleteDialog" widgetVar="deleteDlg" showEffect="fade" hideEffect="explode" header="Confirm" severity="alert" modal="true"> <h:panelGrid id="display" columns="2" cellpadding="4" style="margin:0 auto;"> <h:outputText value="Are you sure you want to delete?" /> <h:outputText value=" "/> <h:outputText value="#{vehiTypeListMngr.selectedVehiType.type}" style="font-weight:bold" /> <h:outputText value=" "/> <p:commandButton id="confirm" value="Yes" type="button" actionListener= "#{vehiTypeListMngr.deletVehicleType((vehiTypeListMngr.selectedVehiType))}" styleClass="ui-confirmdialog-yes" icon="pi pi-check" update=":formListVehiType:vTypeTable" oncomplete="deleteDlg.hide()"/> <p:commandButton value="No " type="button" styleClass="ui-confirmdialog-no" icon="pi pi-times" onclick="deleteDlg.hide()" /> </h:panelGrid> </p:dialog> </h:form> </h:body>
The Managed bean :
import javax.faces.view.ViewScoped; import javax.inject.Named; @Named(value = "vehiTypeListMngr") @ViewScoped public class VehicleTypeListManager extends CommonUtilsJSF implements Serializable { private static final long serialVersionUID = 4966431989099484036L; private static Logger _logger = LogManager.getLogger(VehicleTypeListManager.class); @EJB private TravelService travelService; private String searchString = ""; private List<VehicleTypeTO> vehiTypes; private VehicleTypeTO selectedVehiType; public void deletVehicleType() { try { travelService.deleteVehicleType(selectedVehiType.getVehicleTypeId()); vehiTypes.remove(selectedVehiType); addInfoMessage(String.format("Vehicle Type %s deleted.", selectedVehiType.getType())); selectedVehiType = null; } catch(CabSysAppException ex) { String errMsg = String.format("Error while deleting Vehicle Type : %s -> %s", selectedVehiType.getType(), ex.getMessage()); _logger.debug(errMsg); addExceptionMessageError(errMsg); } }