0

this is my delete code:

                       <!--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-->

This is my confirm dialog:

<!--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-->

And this is my 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");
}}

The problem is when i press "Si" on the confirm dialog, the log send a error:

attempt to create delete event with null entity

The code delete fine without the confirm dialog. I'm using NetBeans 8.2, Primefaces 6.0 and Hibernate 4.3

1 Answers1

0

I resolve my problem, i changed this:

@Named(value = "eliminarAsesorManagedBean")
@RequestScoped

To:

@ManagedBean(name = "eliminarAsesorManagedBean")
@ViewScoped