这是我的删除代码:
<!--Borrar Asesor-->
<p:column headerText="Eliminar" exportable="false" style="width:80px">
<p:commandButton value="Eliminar" update="asesorTable" oncomplete="PF('dlg').show();" immediate="true">
<f:setPropertyActionListener value="#{asesor}" target="#{eliminarAsesorManagedBean.selectedAsesor}" />
</p:commandButton>
</p:column>
<!--Fin Borrar Asesor-->
这是我的确认对话框:
<!--Borrar Asesor Dialogo-->
<p:dialog id="dlg" widgetVar="dlg" header="Eliminar" modal="true" resizable="false" minWidth="160">
<h:form id="formEliminar">
<h:outputText value="¿Desesa eliminar?"/>
<p:commandButton value="Si" actionListener="#{eliminarAsesorManagedBean.eliminarAsesor()}"
oncomplete="dlg.hide()"/>
<p:commandButton value="No" onclick="dlg.hide();"/>
</h:form>
</p:dialog>
<!--Fin Borrar Asesor Dialogo-->
这是我的Managed Bean:
public class EliminarAsesorManagedBean {
private Asesor selectedAsesor;
@Inject //Inyección de implementación
private AsesorService asesorService;
public Asesor getSelectedAsesor() {
return selectedAsesor;
}
public void setSelectedAsesor(Asesor selectedAsesor) {
this.selectedAsesor = selectedAsesor;
}
public EliminarAsesorManagedBean() {
}
public void eliminarAsesor() throws IOException {
asesorService.eliminarAsesor(selectedAsesor);
ExternalContext con = FacesContext.getCurrentInstance().getExternalContext();
con.redirect("administrarAsesores.xhtml");
}}
问题是当我在确认对话框中按“Si”时,日志发送错误:
attempt to create delete event with null entity
没有确认对话框,代码删除正常。我正在使用NetBeans 8.2,Primefaces 6.0和Hibernate 4.3
答案 0 :(得分:0)
我解决了我的问题,我改变了这个:
@Named(value = "eliminarAsesorManagedBean")
@RequestScoped
要:
@ManagedBean(name = "eliminarAsesorManagedBean")
@ViewScoped