更新primefaces数据表nullpointerException

时间:2014-12-07 19:32:00

标签: jsf primefaces nullpointerexception

我正在尝试更新datable中的一行,但我得到空指针异常。 之前,它只是一个简单的添加,更新,删除bean。一切正常。 但是当我添加添加操作对话框时,我想要更新我的行时出错了。当我首先尝试添加操作对话框时,添加操作对话框和更新对话框似乎使用相同的ID。 当我首先尝试更新对话框时,我得到nullPointer。 所以如果你有办法解决这个问题,请不要犹豫。

déc. 07, 2014 7:23:51 PM com.sun.faces.lifecycle.InvokeApplicationPhase execute
AVERTISSEMENT: java.lang.NullPointerException
javax.el.ELException: java.lang.NullPointerException
    at org.apache.el.parser.AstValue.invoke(AstValue.java:197)
    at org.apache.el.MethodExpressionImpl.invoke(MethodExpressionImpl.java:276)
    at javax.faces.event.MethodExpressionActionListener.processAction(MethodExpressionActionListener.java:149)
    at javax.faces.event.ActionEvent.processListener(ActionEvent.java:88)
    at javax.faces.component.UIComponentBase.broadcast(UIComponentBase.java:813)
    at javax.faces.component.UICommand.broadcast(UICommand.java:300)
    at javax.faces.component.UIViewRoot.broadcastEvents(UIViewRoot.java:790)
    at javax.faces.component.UIViewRoot.processApplication(UIViewRoot.java:1282)
    at com.sun.faces.lifecycle.InvokeApplicationPhase.execute(InvokeApplicationPhase.java:81)
    at com.sun.faces.lifecycle.Phase.doPhase(Phase.java:101)
    at com.sun.faces.lifecycle.LifecycleImpl.execute(LifecycleImpl.java:198)
    at javax.faces.webapp.FacesServlet.service(FacesServlet.java:646)
    at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:290)
    at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
    at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:233)
    at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:191)
    at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:127)
    at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:102)
    at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:109)
    at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:298)
    at org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:857)
    at org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.process(Http11Protocol.java:588)
    at org.apache.tomcat.util.net.JIoEndpoint$Worker.run(JIoEndpoint.java:489)
    at java.lang.Thread.run(Thread.java:745)
Caused by: java.lang.NullPointerException
    at controller.ProfilBean.update(ProfilBean.java:58)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
    at java.lang.reflect.Method.invoke(Method.java:606)
    at org.apache.el.parser.AstValue.invoke(AstValue.java:191)
    ... 23 more

déc. 07, 2014 7:23:51 PM com.sun.faces.context.ExceptionHandlerImpl log
1100: JSF1073 : javax.faces.FacesException intercepté durant le traitement de INVOKE_APPLICATION 5 : UIComponent-ClientId=, Message=java.lang.NullPointerException
déc. 07, 2014 7:23:51 PM com.sun.faces.context.ExceptionHandlerImpl log
1100: java.lang.NullPointerException
javax.faces.FacesException: java.lang.NullPointerException
    at com.sun.faces.lifecycle.InvokeApplicationPhase.execute(InvokeApplicationPhase.java:89)
    at com.sun.faces.lifecycle.Phase.doPhase(Phase.java:101)
    at com.sun.faces.lifecycle.LifecycleImpl.execute(LifecycleImpl.java:198)
    at javax.faces.webapp.FacesServlet.service(FacesServlet.java:646)
    at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:290)
    at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
    at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:233)
    at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:191)
    at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:127)
    at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:102)
    at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:109)
    at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:298)
    at org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:857)
    at org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.process(Http11Protocol.java:588)
    at org.apache.tomcat.util.net.JIoEndpoint$Worker.run(JIoEndpoint.java:489)
    at java.lang.Thread.run(Thread.java:745)
Caused by: javax.el.ELException: java.lang.NullPointerException
    at org.apache.el.parser.AstValue.invoke(AstValue.java:197)
    at org.apache.el.MethodExpressionImpl.invoke(MethodExpressionImpl.java:276)
    at javax.faces.event.MethodExpressionActionListener.processAction(MethodExpressionActionListener.java:149)
    at javax.faces.event.ActionEvent.processListener(ActionEvent.java:88)
    at javax.faces.component.UIComponentBase.broadcast(UIComponentBase.java:813)
    at javax.faces.component.UICommand.broadcast(UICommand.java:300)
    at javax.faces.component.UIViewRoot.broadcastEvents(UIViewRoot.java:790)
    at javax.faces.component.UIViewRoot.processApplication(UIViewRoot.java:1282)
    at com.sun.faces.lifecycle.InvokeApplicationPhase.execute(InvokeApplicationPhase.java:81)
    ... 15 more
Caused by: java.lang.NullPointerException
    at controller.ProfilBean.update(ProfilBean.java:58)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
    at java.lang.reflect.Method.invoke(Method.java:606)
    at org.apache.el.parser.AstValue.invoke(AstValue.java:191)
    ... 23 more

profil.xhtml

<h:body style="background-color: #ECF3FD;">
    <h:form id="form" style="width:800px;">
        <p:growl id="message" showDetail="true" />

        <p:dataTable tableStyle="width:800px;" id="display" var="listeProfils"
            value="#{profilBean.listeProfils}" editable="true"
            style="margin-bottom:10px" rowKey="#{listeProfils.idProfil}"
            selection="#{profilBean.profil}" selectionMode="single">

            <f:facet name="header">
           Liste des profils
       </f:facet>


            <p:column headerText="Id Profil">
                <p:cellEditor>
                    <f:facet name="output">
                        <h:outputText value="#{listeProfils.idProfil}" />
                    </f:facet>
                    <f:facet name="input">
                        <p:inputText id="modelInput" value="#{listeProfils.idProfil}"
                            style="width:100%" />
                    </f:facet>
                </p:cellEditor>
            </p:column>

            <p:column headerText="Libellé profil">
                <p:cellEditor>
                    <f:facet name="output">
                        <h:outputText value="#{listeProfils.libelleProfil}" />
                    </f:facet>
                    <f:facet name="input">
                        <p:inputText value="#{listeProfils.libelleProfil}"
                            style="width:100%" label="Year" />
                    </f:facet>
                </p:cellEditor>
            </p:column>


            <p:column headerText="Modifier">
                <p:commandLink styleClass="ui-icon ui-icon-pencil" process="@this"
                    update=":form:profilDetail" oncomplete="PF('profilDialog').show()">
                    <f:setPropertyActionListener target="#{profilBean.profil}"
                        value="#{listeProfils}" />
                </p:commandLink>
            </p:column>

            <p:column headerText="Supprimer" styleClass="a-center">
                <p:commandLink styleClass="ui-icon ui-icon-trash"
                    oncomplete="PF('confirmation').show()">
                    <f:setPropertyActionListener target="#{profilBean.profil}"
                        value="#{listeProfils}"></f:setPropertyActionListener>
                </p:commandLink>
            </p:column>
        </p:dataTable>
        <p:commandButton value="Ajouter" oncomplete="PF('ajout').show()"
            icon="ui-icon-circle-plus" />
        <p:dialog header="Ajout Profil" widgetVar="ajout" modal="true"
            showEffect="fade" hideEffect="fade" resizable="false">
            <h:form>

                <p:accordionPanel>
                    <p:tab title=" Ajouter Profil">

                        <h:panelGrid columns="2" cellpadding="10">
                            <h:form id="form2">

                                <h:panelGrid columns="2" cellpadding="5">


                                    <h:outputText value="Libellé profil: " />
                                    <p:inputText value="#{profilBean.libelleProfil}" />

                                </h:panelGrid>

                                <p:separator />
                                <p:commandButton value="Valider" icon="ui-icon-circle-check"
                                    update=":form:display" actionListener="#{profilBean.insert}" />
                                <p:commandButton value="Annuler"
                                    icon="ui-icon-arrowreturnthick-1-w" onclick="ajout.hide();" />


                            </h:form>

                        </h:panelGrid>
                    </p:tab>



                </p:accordionPanel>

            </h:form>



        </p:dialog>

        <p:dialog header="Modification Profil" widgetVar="profilDialog"
            modal="true" showEffect="fade" hideEffect="fade" resizable="false">
            <p:panel id="profilDetail" style="border:none;">
                <p:panelGrid columns="2" rendered="#{not empty profilBean.profil}"
                    columnClasses="label,value" style="border:none;">
                    <p:accordionPanel>
                    <p:tab title=" Modifier Profil">

                            <h:panelGrid styleClass="p" columns="3" cellpadding="5">

                                <h:outputText value="ID profil: " />
                                <h:outputText value="#{profilBean.profil.idProfil}" />
                                <br />
                                <h:outputText value="Libellé Profil: " />
                                <p:inputText value="#{profilBean.profil.libelleProfil}" />


                            </h:panelGrid>

                        </p:tab>


                    </p:accordionPanel>





                </p:panelGrid>
                <p:separator />
                <p:commandButton value="Valider" icon="ui-icon-circle-check"
                    update="display" actionListener="#{profilBean.update}"
                    onclick="profilDialog.hide()" />
                <p:commandButton value="Annuler" icon="ui-icon-arrowreturnthick-1-w"
                    onclick="profilDialog.hide();" />
            </p:panel>

        </p:dialog>

        <p:commandButton value="Ajouter action" update="actionDetail" oncomplete="PF('actionDialog').show()"  icon="ui-icon-circle-plus" />

   <p:dialog header="Ajout action" widgetVar="actionDialog" modal="true" showEffect="fade" hideEffect="fade" resizable="false">
        <p:panel id="actionDetail" style="border:none;">
            <p:panelGrid  columns="2" rendered="#{not empty profilBean.profil}" columnClasses="label,value" style="border:none;">
              <p:accordionPanel>
                    <p:tab title="Ajouter action">

                    <h:panelGrid styleClass="p" columns="2"  cellpadding="5">

                <h:outputText value="ID Profil:" />
                <h:outputText value="#{profilBean.profil.idProfil}" />

                <h:outputText value="Libellé Profil: " />
                <h:outputText value="#{profilBean.profil.libelleProfil}" />

                <h:outputText value="Libellé Action: " />
                <p:inputText value="#{profilBean.libelleAction}"/>
                </h:panelGrid>

                    </p:tab>


        </p:accordionPanel>





                </p:panelGrid>
                <p:commandButton value="Valider" icon="ui-icon-circle-check" update="display" onclick="actionDialog.hide();" actionListener="#{profilBean.insertAction}"/>
                <p:commandButton value="Annuler" icon="ui-icon-arrowreturnthick-1-w" onclick="actionDialog.hide();" />
        </p:panel>
    </p:dialog>

    </h:form>
    <p:confirmDialog id="confirmDialog"
        message="Est-ce que vous êtes sûr de supprimer ce profil"
        header="Confirmation de suppression" severity="alert"
        widgetVar="confirmation">
        <h:form>
            <p:commandButton id="confirm" value="Confirmer"
                icon="ui-icon-circle-check" oncomplete="PF('confirmation').hide()"
                update=":form:display :form:message"
                actionListener="#{profilBean.delete}" />
            <p:commandButton id="decline" value="Annuler"
                icon="ui-icon-arrowreturnthick-1-w"
                onclick="PF('confirmation').hide()" type="button" />
        </h:form>
    </p:confirmDialog>
</h:body>
</html>

profilBean.java

@Controller
@Scope("view")
public class ProfilBean implements java.io.Serializable{

    /**
     * 
     */
    private static final long serialVersionUID = 1L;

    @Autowired
    private ProfilMetier profilMetier;
    @Autowired
    private ActionMetier actionMetier;
    private List<Profil> listeProfils;
    private Profil profil;
    private static int idProfil;
    private String libelleProfil;
    private String libelleAction;


    @PostConstruct
    public void init() {

        listeProfils = profilMetier.getAllProfils();
    }

    public void insert()
    {
        Profil profil = new Profil();
        profil.setLibelleProfil(getLibelleProfil());
        profilMetier.insert(profil);
        init();
    }
    public void update()
    {
        Profil p = profilMetier.getProfil(getProfil().getIdProfil());
        p.setIdProfil(getProfil().getIdProfil());
        p.setLibelleProfil(getProfil().getLibelleProfil());
        profilMetier.update(profil);
    }
    public void delete()
    {
        Profil p = profilMetier.getProfil(getProfil().getIdProfil());
        profilMetier.delete(p.getIdProfil());
        listeProfils.remove(profil);
        addMessage("Suppression réussie", "Le Profil "+ profil.getLibelleProfil() +" a été supprimé avec succès.");
        profil=null;
    }
    public void addMessage(String summary, String detail) 
    {
        FacesMessage message = new FacesMessage(FacesMessage.SEVERITY_INFO, summary, detail);
        FacesContext.getCurrentInstance().addMessage(null, message);
    }

    public static int submit()
    {
        return idProfil;
    }

    public void insertAction()
    {
        Action action = new Action();
        String libellea = getLibelleAction();
        action.setLibelleAction(libellea);
        Profil p = profilMetier.getProfil(getProfil().getIdProfil());
        action.setProfil(p);
        actionMetier.insert(action);

    }

//getters and setters
}

0 个答案:

没有答案