Jsf 删除&;datatable列中的确认对话框-删除行-不工作
我使用的是PrimeFacesDataTable,有一列包含delete按钮。我面临着类似的问题,比如:Jsf 删除&;datatable列中的确认对话框-删除行-不工作,jsf,primefaces,Jsf,Primefaces,我使用的是PrimeFacesDataTable,有一列包含delete按钮。我面临着类似的问题,比如: 我尝试了那里给出的解决方案,但不起作用。在我的例子中,方法vehiTypeListMngr.deletVehicleType注册于的actionListener,问题似乎在于没有触发actionListener。这可能有不同的原因。我建议您通过创建一个带有表单和按钮的简单页面来检查为什么actionListener没有启动。可能存在一些与Primefaces的Ajax相关的配置问题。还要检查
我尝试了那里给出的解决方案,但不起作用。在我的例子中,方法
vehiTypeListMngr.deletVehicleType
注册于的actionListener
,问题似乎在于没有触发actionListener。这可能有不同的原因。我建议您通过创建一个带有表单和按钮的简单页面来检查为什么actionListener没有启动。可能存在一些与Primefaces的Ajax相关的配置问题。还要检查你的浏览器中是否启用了JavaScript。我在一个单独的页面中尝试了你的示例,它运行正常。在我的确认对话框中,我为是和否按钮设置了type=“button”,因此它不起作用。已删除type=“button”,现在显示确认对话框,但对象selectedVehicleType
为空。现在也将调用方法deletVehicleType(VehicleTypeTO selectedVehicleType)
,但传递给它的参数selectedVehicleType
为空。可能有什么问题?您需要从数据表的按钮更新对话框。还可以在oncomplete而不是onclick上打开对话框,因为oncomplete是在更新完成后激发的。@TapasBose现在显示的对话框带有selectedVehicleType值,您不需要将该值作为参数传递给actionListener。您的ManagedBean中已经有了它。因此,当该对话框的delete按钮的actionListener被触发时,相应的方法将拥有它。另外,请通过编辑您的问题来更新您的代码。
<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>
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);
}
}