引起:javax.el.E​​LException:读取“montantFacture'在类型controller.DisponibleBean,java.lang.NullPointerException上

时间:2014-06-08 21:33:14

标签: java spring hibernate jsf

我正在研究jsf,spring和hibernate,我必须根据selectOneMenu显示一些值。 我的代码正在运行,但突然间,它只是不再工作了 这是我得到的例外:

08-Jun-2014 22:27:27.679 SEVERE [http-nio-8084-exec-64] com.sun.faces.application.view.FaceletViewHandlingStrategy.handleRenderException Error Rendering View[/facture2.xhtml]
 javax.el.ELException: /facture2.xhtml @33,80 value="#{disponibleBean.montantFacture}": Error reading 'montantFacture' on type controller.DisponibleBean
    at com.sun.faces.facelets.el.TagValueExpression.getValue(TagValueExpression.java:114)
    at javax.faces.component.ComponentStateHelper.eval(ComponentStateHelper.java:194)
    at javax.faces.component.ComponentStateHelper.eval(ComponentStateHelper.java:182)
    at javax.faces.component.UIOutput.getValue(UIOutput.java:174)
    at com.sun.faces.renderkit.html_basic.HtmlBasicInputRenderer.getValue(HtmlBasicInputRenderer.java:205)
    at com.sun.faces.renderkit.html_basic.HtmlBasicRenderer.getCurrentValue(HtmlBasicRenderer.java:355)
    at com.sun.faces.renderkit.html_basic.HtmlBasicRenderer.encodeEnd(HtmlBasicRenderer.java:164)
    at javax.faces.component.UIComponentBase.encodeEnd(UIComponentBase.java:919)
    at com.sun.faces.renderkit.html_basic.HtmlBasicRenderer.encodeRecursive(HtmlBasicRenderer.java:312)
    at com.sun.faces.renderkit.html_basic.GridRenderer.renderRow(GridRenderer.java:185)
1
1
c =1000.0
1
1
    at com.sun.faces.renderkit.html_basic.GridRenderer.encodeChildren(GridRenderer.java:129)
    at javax.faces.component.UIComponentBase.encodeChildren(UIComponentBase.java:889)
    at org.primefaces.renderkit.CoreRenderer.renderChild(CoreRenderer.java:70)
    at org.primefaces.renderkit.CoreRenderer.renderChildren(CoreRenderer.java:57)
    at org.primefaces.component.panel.PanelRenderer.encodeContent(PanelRenderer.java:204)
    at org.primefaces.component.panel.PanelRenderer.encodeMarkup(PanelRenderer.java:121)
    at org.primefaces.component.panel.PanelRenderer.encodeEnd(PanelRenderer.java:58)
    at javax.faces.component.UIComponentBase.encodeEnd(UIComponentBase.java:919)
    at javax.faces.component.UIComponent.encodeAll(UIComponent.java:1903)
    at javax.faces.render.Renderer.encodeChildren(Renderer.java:176)
    at javax.faces.component.UIComponentBase.encodeChildren(UIComponentBase.java:889)
    at com.sun.faces.renderkit.html_basic.HtmlBasicRenderer.encodeRecursive(HtmlBasicRenderer.java:304)
    at com.sun.faces.renderkit.html_basic.GridRenderer.renderRow(GridRenderer.java:185)
    at com.sun.faces.renderkit.html_basic.GridRenderer.encodeChildren(GridRenderer.java:129)
    at javax.faces.component.UIComponentBase.encodeChildren(UIComponentBase.java:889)
    at javax.faces.component.UIComponent.encodeAll(UIComponent.java:1896)
    at javax.faces.component.UIComponent.encodeAll(UIComponent.java:1899)
    at org.primefaces.component.accordionpanel.AccordionPanelRenderer.encodeTab(AccordionPanelRenderer.java:227)
    at org.primefaces.component.accordionpanel.AccordionPanelRenderer.encodeTabs(AccordionPanelRenderer.java:156)
    at org.primefaces.component.accordionpanel.AccordionPanelRenderer.encodeMarkup(AccordionPanelRenderer.java:103)
    at org.primefaces.component.accordionpanel.AccordionPanelRenderer.encodeEnd(AccordionPanelRenderer.java:76)
    at javax.faces.component.UIComponentBase.encodeEnd(UIComponentBase.java:919)
    at javax.faces.component.UIComponent.encodeAll(UIComponent.java:1903)
    at javax.faces.render.Renderer.encodeChildren(Renderer.java:176)
    at javax.faces.component.UIComponentBase.encodeChildren(UIComponentBase.java:889)
    at javax.faces.component.UIComponent.encodeAll(UIComponent.java:1896)
    at javax.faces.component.UIComponent.encodeAll(UIComponent.java:1899)
    at javax.faces.component.UIComponent.encodeAll(UIComponent.java:1899)
    at com.sun.faces.application.view.FaceletViewHandlingStrategy.renderView(FaceletViewHandlingStrategy.java:451)
    at com.sun.faces.application.view.MultiViewHandler.renderView(MultiViewHandler.java:131)
    at com.sun.faces.lifecycle.RenderResponsePhase.execute(RenderResponsePhase.java:120)
    at com.sun.faces.lifecycle.Phase.doPhase(Phase.java:101)
    at com.sun.faces.lifecycle.LifecycleImpl.render(LifecycleImpl.java:219)
    at javax.faces.webapp.FacesServlet.service(FacesServlet.java:647)
    at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:301)
    at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
    at org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:52)
    at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:239)
    at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
    at org.netbeans.modules.web.monitor.server.MonitorFilter.doFilter(MonitorFilter.java:393)
    at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:239)
    at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
    at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:219)
    at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:106)
    at org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:503)
    at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:136)
    at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:74)
    at org.apache.catalina.valves.AbstractAccessLogValve.invoke(AbstractAccessLogValve.java:610)
    at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:88)
    at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:516)
    at org.apache.coyote.http11.AbstractHttp11Processor.process(AbstractHttp11Processor.java:1015)
    at org.apache.coyote.AbstractProtocol$AbstractConnectionHandler.process(AbstractProtocol.java:652)
    at org.apache.coyote.http11.Http11NioProtocol$Http11ConnectionHandler.process(Http11NioProtocol.java:222)
    at org.apache.tomcat.util.net.NioEndpoint$SocketProcessor.doRun(NioEndpoint.java:1575)
    at org.apache.tomcat.util.net.NioEndpoint$SocketProcessor.run(NioEndpoint.java:1533)
    at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142)
    at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617)
    at java.lang.Thread.run(Thread.java:745)
Caused by: javax.el.ELException: Error reading 'montantFacture' on type controller.DisponibleBean
    at javax.el.BeanELResolver.getValue(BeanELResolver.java:108)
    at com.sun.faces.el.DemuxCompositeELResolver._getValue(DemuxCompositeELResolver.java:176)
    at com.sun.faces.el.DemuxCompositeELResolver.getValue(DemuxCompositeELResolver.java:203)
    at org.apache.el.parser.AstValue.getValue(AstValue.java:167)
    at org.apache.el.ValueExpressionImpl.getValue(ValueExpressionImpl.java:187)
    at com.sun.faces.facelets.el.TagValueExpression.getValue(TagValueExpression.java:109)
    ... 67 more
Caused by: java.lang.NullPointerException
    at controller.DisponibleBean.getMontantFacture(DisponibleBean.java:30)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
    at java.lang.reflect.Method.invoke(Method.java:483)
    at javax.el.BeanELResolver.getValue(BeanELResolver.java:97)
    ... 72 more

Facture.xhtml

<?xml version='1.0' encoding='UTF-8' ?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml"
      xmlns:h="http://xmlns.jcp.org/jsf/html"
      xmlns:f="http://xmlns.jcp.org/jsf/core"
      xmlns:p="http://primefaces.org/ui">
    <h:head>
        <title>Facelet Title</title>
    </h:head>
    <h:body>
          <h:form>

            <p:accordionPanel>
                    <p:tab title="Engager Facture">

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

                            <p:panel header="Facture" id="panel">
                                <h:panelGrid columns="3" cellpadding="5">
       <h:outputText value="Rubrique: " />
                            <p:selectOneMenu value="#{rubriqueBean.idRubrique}" >
        <f:selectItem itemValue="#{null}" itemLabel="-- select one --" />
        <f:selectItems value="#{rubriqueBean.listeRubriques}" var="rubrique" 
                       itemValue="#{rubrique.idRubrique}" itemLabel="#{rubrique.libelleRubrique}" />
        <f:ajax listener="#{rubriqueBean.submit1()}" render="display1 display2 display3"/>
    </p:selectOneMenu>
       <br/>
       <h:outputText value="Cre: " />
        <h:outputText id="display1" value="#{disponibleBean.creditOuvert}" />
       <br/>
        <h:outputText value="Montant: " />
        <h:outputText id="display2" value="#{disponibleBean.montantFacture}" />
       <br/>
      <h:outputText value="Disponible: " />
        <h:outputText id="display3" value="#{disponibleBean.disponible}" />
       <br/>
       </h:panelGrid>
        </p:panel>

                        </h:form>

                    </h:panelGrid>
                </p:tab>
                </p:accordionPanel>
         </h:form>
    </h:body>
</html>

DisponibleBean.java

package controller;

import java.util.List;
import model.services.BudgetisationMetier;
import model.services.FactureMetier;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Scope;
import org.springframework.stereotype.Component;

@Component
@Scope("view")
public class DisponibleBean implements java.io.Serializable{

    @Autowired
    private static FactureMetier factureMetier;
    @Autowired
    private BudgetisationMetier budgetisationMetier;
    private List<Object> listeFactures;
    private List<Object> listeBudgets;
    private double montantFacture;
    private double creditOuvert;
    private double disponible;

    public double getMontantFacture() {
        int id = RubriqueBean.submit1();
        System.out.println(id);
        if(id != 0)
        {
            listeFactures = factureMetier.getMontantFacture(id);
            montantFacture = (double)listeFactures.get(0);
            System.out.println("m =" + montantFacture);
            return montantFacture;
        }
        return montantFacture;
    }

    public double getCreditOuvert() {
       int id = RubriqueBean.submit1();
        System.out.println(id);
        if(id != 0)
        {
            listeBudgets = budgetisationMetier.getCreditOuvert(id);
            creditOuvert = (double)listeBudgets.get(0);
            System.out.println("c =" + creditOuvert);
            return creditOuvert;
        }
        return creditOuvert;
    }

    public double getDisponible()
    {
            disponible = creditOuvert - montantFacture;
            System.out.println("d =" + disponible);
            return disponible;
    }
}

感谢您的帮助

0 个答案:

没有答案