显示java.lang.NullPointerException

时间:2015-11-29 16:05:08

标签: java jsf primefaces nullpointerexception

当我尝试通过以下xhtml中的代码访问托管bean的登录方法时:

   <p:commandButton value="Login" actionListener="#{login.log}" styleClass="btn btn-danger btn-lg btn-block" update="growl"/>

我的Login类看起来像这样:

@ManagedBean(name = "login")
@ViewScoped
public class LoginBean implements Serializable {

    private static final long serialVersionUID = 1L;

    @ManagedProperty("#{userImpService}")
    private UserImpService userImpService;


    public UserImpService getUserImpService() {
        return userImpService;
    }

    public void setUserImpService(
            UserImpService userImpService) {
        this.userImpService = userImpService;
    }

    private String userName;
    private String passWord;

    public String getUserName() {
        return userName;
    }

    public void setUserName(String userName) {
        this.userName = userName;
    }

    public String getPassWord() {
        return passWord;
    }

    public void setPassWord(String passWord) {
        this.passWord = passWord;
    }

    public void log(ActionEvent event) {



        if (getUserName().equals(""))
            FacesContext.getCurrentInstance().addMessage(
                    null,
                    new FacesMessage(FacesMessage.SEVERITY_ERROR, "erreur!",
                            "champ identifient vide "));

        if (getPassWord().equals(""))
            FacesContext.getCurrentInstance().addMessage(
                    null,
                    new FacesMessage(FacesMessage.SEVERITY_WARN, "erreur!",
                            "champ mot de passe vide "));

        FacesContext.getCurrentInstance().addMessage(
                null,
                new FacesMessage(FacesMessage.SEVERITY_ERROR, "erreur!",
                        "identifient et mot de passe invalide "));
        System.out.println("Etape JSF .................... Che");
        boolean b = userImpService.searchProfil("","");

    }

当我调用boolean b = userImpService.searchProfil(“”,“”);它给了我以下错误:

com.sun.faces.lifecycle.InvokeApplicationPhase execute
AVERTISSEMENT: /views/login.xhtml @70,132 actionListener="#{login.log}": java.lang.NullPointerException
javax.el.ELException: /views/login.xhtml @70,132 actionListener="#{login.log}": java.lang.NullPointerException
    at com.sun.faces.facelets.el.TagMethodExpression.invoke(Unknown Source)
    at javax.faces.event.MethodExpressionActionListener.processAction(Unknown Source)
    at javax.faces.event.ActionEvent.processListener(Unknown Source)
    at javax.faces.component.UIComponentBase.broadcast(Unknown Source)
    at javax.faces.component.UICommand.broadcast(Unknown Source)
    at javax.faces.component.UIViewRoot.broadcastEvents(Unknown Source)
    at javax.faces.component.UIViewRoot.processApplication(Unknown Source)
    at com.sun.faces.lifecycle.InvokeApplicationPhase.execute(Unknown Source)
    at com.sun.faces.lifecycle.Phase.doPhase(Unknown Source)
    at com.sun.faces.lifecycle.LifecycleImpl.execute(Unknown Source)
    at javax.faces.webapp.FacesServlet.service(Unknown Source)
    at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:303)
    at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:208)
    at org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:52)
    at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:241)
    at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:208)
    at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:220)
    at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:122)
    at org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:505)
    at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:170)
    at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:103)
    at org.apache.catalina.valves.AccessLogValve.invoke(AccessLogValve.java:956)
    at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:116)
    at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:423)
    at org.apache.coyote.http11.AbstractHttp11Processor.process(AbstractHttp11Processor.java:1079)
    at org.apache.coyote.AbstractProtocol$AbstractConnectionHandler.process(AbstractProtocol.java:625)
    at org.apache.tomcat.util.net.JIoEndpoint$SocketProcessor.run(JIoEndpoint.java:318)
    at java.util.concurrent.ThreadPoolExecutor.runWorker(Unknown Source)
    at java.util.concurrent.ThreadPoolExecutor$Worker.run(Unknown Source)
    at org.apache.tomcat.util.threads.TaskThread$WrappingRunnable.run(TaskThread.java:61)
    at java.lang.Thread.run(Unknown Source)
Caused by: java.lang.NullPointerException
    at primefaces.presentation.LoginBean.log(LoginBean.java:74)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
    at java.lang.reflect.Method.invoke(Unknown Source)
    at org.apache.el.parser.AstValue.invoke(AstValue.java:278)
    at org.apache.el.MethodExpressionImpl.invoke(MethodExpressionImpl.java:273)
    ... 31 more

nov. 29, 2015 4:02:42 PM com.sun.faces.context.AjaxExceptionHandlerImpl handlePartialResponseError
GRAVE: java.lang.NullPointerException
    at primefaces.presentation.LoginBean.log(LoginBean.java:74)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
    at java.lang.reflect.Method.invoke(Unknown Source)
    at org.apache.el.parser.AstValue.invoke(AstValue.java:278)
    at org.apache.el.MethodExpressionImpl.invoke(MethodExpressionImpl.java:273)
    at com.sun.faces.facelets.el.TagMethodExpression.invoke(Unknown Source)
    at javax.faces.event.MethodExpressionActionListener.processAction(Unknown Source)
    at javax.faces.event.ActionEvent.processListener(Unknown Source)
    at javax.faces.component.UIComponentBase.broadcast(Unknown Source)
    at javax.faces.component.UICommand.broadcast(Unknown Source)
    at javax.faces.component.UIViewRoot.broadcastEvents(Unknown Source)
    at javax.faces.component.UIViewRoot.processApplication(Unknown Source)
    at com.sun.faces.lifecycle.InvokeApplicationPhase.execute(Unknown Source)
    at com.sun.faces.lifecycle.Phase.doPhase(Unknown Source)
    at com.sun.faces.lifecycle.LifecycleImpl.execute(Unknown Source)
    at javax.faces.webapp.FacesServlet.service(Unknown Source)
    at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:303)
    at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:208)
    at org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:52)
    at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:241)
    at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:208)
    at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:220)
    at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:122)
    at org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:505)
    at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:170)
    at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:103)
    at org.apache.catalina.valves.AccessLogValve.invoke(AccessLogValve.java:956)
    at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:116)
    at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:423)
    at org.apache.coyote.http11.AbstractHttp11Processor.process(AbstractHttp11Processor.java:1079)
    at org.apache.coyote.AbstractProtocol$AbstractConnectionHandler.process(AbstractProtocol.java:625)
    at org.apache.tomcat.util.net.JIoEndpoint$SocketProcessor.run(JIoEndpoint.java:318)
    at java.util.concurrent.ThreadPoolExecutor.runWorker(Unknown Source)
    at java.util.concurrent.ThreadPoolExecutor$Worker.run(Unknown Source)
    at org.apache.tomcat.util.threads.TaskThread$WrappingRunnable.run(TaskThread.java:61)
    at java.lang.Thread.run(Unknown Source)

0 个答案:

没有答案