title: PrimeFaces: javax.el.ELException adding a menu choice
body: <p>I'm trying to port an application from RichFaces to PrimeFaces to check the performance differences. When I add the Logout menu choice (that works using RIchFaces)...</p>
  
  <pre><code>&lt;h:form&gt;
     &lt;p:toolbar&gt;
        &lt;p:toolbarGroup align="left"&gt;  
            &lt;p:menubar&gt;  
               &lt;p:submenu label="My Account" icon="ui-icon-person"&gt;  
               &lt;p:menuitem  value="Modify my Data" url="#{participantBean.modifyUser(participantBean.principal)}" icon="ui-icon-pencil" /&gt;
               &lt;p:menuitem  value="Change Password" url="#{participantBean.modifyPassword(participantBean.principal)}" /&gt;
               &lt;p:menuitem  value="Logout" url="#{auth.logout()}" /&gt;
            &lt;/p:submenu&gt;
           &lt;/p:menubar&gt;
        &lt;/p:toolbarGroup&gt;
      &lt;/p:toolbar&gt;
  &lt;/h:form&gt;
  </code></pre>
  
  <p>I receive the following exception</p>
  
  <pre><code>javax.el.ELException: /secure/index.xhtml @30,85 url="#{auth.logout()}":     java.lang.IllegalStateException
  at com.sun.faces.facelets.el.TagValueExpression.getValue(TagValueExpression.java:114)
  at javax.faces.component.ComponentStateHelper.eval(ComponentStateHelper.java:194)
  at org.primefaces.component.menuitem.UIMenuItem.getUrl(UIMenuItem.java:99)
  at org.primefaces.component.menuitem.UIMenuItem.getHref(UIMenuItem.java:292)
  at    org.primefaces.renderkit.OutcomeTargetRenderer.getTargetURL(OutcomeTargetRenderer.java:73)
  at org.primefaces.component.menu.BaseMenuRenderer.encodeMenuItem(BaseMenuRenderer.java:148)
  at org.primefaces.component.tieredmenu.TieredMenuRenderer.encodeElements(TieredMenuRenderer.java:103)
  at org.primefaces.component.tieredmenu.TieredMenuRenderer.encodeSubmenu(TieredMenuRenderer.java:162)
  at org.primefaces.component.tieredmenu.TieredMenuRenderer.encodeElements(TieredMenuRenderer.java:119)
  at org.primefaces.component.tieredmenu.TieredMenuRenderer.encodeMenu(TieredMenuRenderer.java:78)
  at org.primefaces.component.menubar.MenubarRenderer.encodeMarkup(MenubarRenderer.java:49)
  at org.primefaces.component.menu.BaseMenuRenderer.encodeEnd(BaseMenuRenderer.java:105)
  at javax.faces.component.UIComponentBase.encodeEnd(UIComponentBase.java:875)
  at javax.faces.component.UIComponent.encodeAll(UIComponent.java:1764)
  at org.primefaces.component.toolbar.ToolbarRenderer.encodeEnd(ToolbarRenderer.java:61)
  at javax.faces.component.UIComponentBase.encodeEnd(UIComponentBase.java:875)
  at javax.faces.component.UIComponent.encodeAll(UIComponent.java:1764)
  at javax.faces.render.Renderer.encodeChildren(Renderer.java:168)
  at javax.faces.component.UIComponentBase.encodeChildren(UIComponentBase.java:845)
  at javax.faces.component.UIComponent.encodeAll(UIComponent.java:1757)
  at javax.faces.component.UIComponent.encodeAll(UIComponent.java:1760)
  at javax.faces.component.UIComponent.encodeAll(UIComponent.java:1760)
  at com.sun.faces.application.view.FaceletViewHandlingStrategy.renderView(FaceletViewHandlingStrategy.java:402)
  at com.sun.faces.application.view.MultiViewHandler.renderView(MultiViewHandler.java:131)
  at javax.faces.application.ViewHandlerWrapper.renderView(ViewHandlerWrapper.java:288)
  at com.sun.faces.lifecycle.RenderResponsePhase.execute(RenderResponsePhase.java:121)
  at com.sun.faces.lifecycle.Phase.doPhase(Phase.java:101)
  at com.sun.faces.lifecycle.LifecycleImpl.render(LifecycleImpl.java:139)
  at javax.faces.webapp.FacesServlet.service(FacesServlet.java:594)
  at org.apache.catalina.core.StandardWrapper.service(StandardWrapper.java:1550)
  at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:281)
  at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:175)
  at org.apache.catalina.core.StandardPipeline.doInvoke(StandardPipeline.java:655)
  at org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:595)
  at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:161)
  at org.apache.catalina.connector.CoyoteAdapter.doService(CoyoteAdapter.java:331)
  at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:231)
  at com.sun.enterprise.v3.services.impl.ContainerMapper$AdapterCallable.call(ContainerMapper.java:317)
  at com.sun.enterprise.v3.services.impl.ContainerMapper.service(ContainerMapper.java:195)
  at com.sun.grizzly.http.ProcessorTask.invokeAdapter(ProcessorTask.java:860)
  at com.sun.grizzly.http.ProcessorTask.doProcess(ProcessorTask.java:757)
  at com.sun.grizzly.http.ProcessorTask.process(ProcessorTask.java:1056)
  at com.sun.grizzly.http.DefaultProtocolFilter.execute(DefaultProtocolFilter.java:229)
  at com.sun.grizzly.DefaultProtocolChain.executeProtocolFilter(DefaultProtocolChain.java:137)
  at com.sun.grizzly.DefaultProtocolChain.execute(DefaultProtocolChain.java:104)
  at com.sun.grizzly.DefaultProtocolChain.execute(DefaultProtocolChain.java:90)
  at com.sun.grizzly.http.HttpProtocolChain.execute(HttpProtocolChain.java:79)
  at com.sun.grizzly.ProtocolChainContextTask.doCall(ProtocolChainContextTask.java:54)
  at com.sun.grizzly.SelectionKeyContextTask.call(SelectionKeyContextTask.java:59)
  at com.sun.grizzly.ContextTask.run(ContextTask.java:71)
  at com.sun.grizzly.util.AbstractThreadPool$Worker.doWork(AbstractThreadPool.java:532)
  at com.sun.grizzly.util.AbstractThreadPool$Worker.run(AbstractThreadPool.java:513)
  at java.lang.Thread.run(Thread.java:662)
    Caused by: java.lang.IllegalStateException
  at org.apache.catalina.connector.ResponseFacade.sendRedirect(ResponseFacade.java:524)
  at com.sun.faces.context.ExternalContextImpl.redirect(ExternalContextImpl.java:576)
  at Beans.Auth.logout(Auth.java:73)
  at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
  at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
  at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
  at java.lang.reflect.Method.invoke(Method.java:597)
  at javax.el.BeanELResolver.invokeMethod(BeanELResolver.java:779)
  at javax.el.BeanELResolver.invoke(BeanELResolver.java:528)
  at javax.el.CompositeELResolver.invoke(CompositeELResolver.java:257)
  at com.sun.el.parser.AstValue.getValue(AstValue.java:134)
  at com.sun.el.parser.AstValue.getValue(AstValue.java:183)
  at com.sun.el.ValueExpressionImpl.getValue(ValueExpressionImpl.java:224)
  at org.jboss.weld.el.WeldValueExpression.getValue(WeldValueExpression.java:50)
  at com.sun.faces.facelets.el.TagValueExpression.getValue(TagValueExpression.java:109)
  ... 52 more
  </code></pre>
  
  <p>The logout method is in the Auth bean:</p>
  
  <pre><code>public class Auth implements Serializable {
  
  /**
   * Creates a new instance of Auth
   */
  public Auth() {
  }
  private static final long serialVersionUID = 1L;
  @Inject
  private ParticipantDAO userService;
  private String email;
  private String password;
  private String originalURL;
  
  @PostConstruct
  public void init() {
      ExternalContext externalContext = FacesContext.getCurrentInstance().getExternalContext();
      originalURL = (String) externalContext.getRequestMap().get(RequestDispatcher.FORWARD_REQUEST_URI);
  
      if (originalURL == null) {
          originalURL = externalContext.getRequestContextPath() + "/secure/index.xhtml";
      } else {
          String originalQuery = (String) externalContext.getRequestMap().get(RequestDispatcher.FORWARD_QUERY_STRING);
  
          if (originalQuery != null) {
              originalURL += "?" + originalQuery;
          }
      }
  }
  
  public void login() throws IOException, ServletException {
      FacesContext context = FacesContext.getCurrentInstance();
      ExternalContext externalContext = context.getExternalContext();
      HttpServletRequest request = (HttpServletRequest) externalContext.getRequest();
  
      try {
          request.login(email, password);
          Participant user = userService.findUser(email, password);
          externalContext.getSessionMap().put("user", user);
          externalContext.redirect(originalURL);
      } catch (ServletException e) {
          // Handle unknown username/password in request.login().
          context.addMessage(null, new FacesMessage("Unknown login or wrong password"));
      }
  }
  
  public void logout() throws IOException {
      ExternalContext externalContext = FacesContext.getCurrentInstance().getExternalContext();
      externalContext.invalidateSession();
      externalContext.redirect(externalContext.getRequestContextPath() + "/secure/login.xhtml");
  }
  </code></pre>
  
  <p>Where I wrong?</p>
  
  <hr>
  
  <p>If I apply your modification I obtain:</p>
  
  <pre><code>com.sun.faces.mgbean.ManagedBeanCreationException: An error occurred performing resource injection on managed bean participantBean
  at com.sun.faces.mgbean.BeanBuilder.invokePostConstruct(BeanBuilder.java:229)
  at com.sun.faces.mgbean.BeanBuilder.build(BeanBuilder.java:105)
  at com.sun.faces.mgbean.BeanManager.createAndPush(BeanManager.java:409)
  at com.sun.faces.mgbean.BeanManager.create(BeanManager.java:269)
  at com.sun.faces.el.ManagedBeanELResolver.resolveBean(ManagedBeanELResolver.java:244)
  at com.sun.faces.el.ManagedBeanELResolver.getValue(ManagedBeanELResolver.java:116)
  at com.sun.faces.el.DemuxCompositeELResolver._getValue(DemuxCompositeELResolver.java:176)
  at com.sun.faces.el.DemuxCompositeELResolver.getValue(DemuxCompositeELResolver.java:203)
  at com.sun.el.parser.AstIdentifier.getValue(AstIdentifier.java:103)
  at com.sun.el.parser.AstValue.getValue(AstValue.java:179)
  at com.sun.el.ValueExpressionImpl.getValue(ValueExpressionImpl.java:224)
  at org.jboss.weld.el.WeldValueExpression.getValue(WeldValueExpression.java:50)
  at com.sun.faces.facelets.el.ELText$ELTextVariable.writeText(ELText.java:227)
  at com.sun.faces.facelets.el.ELText$ELTextComposite.writeText(ELText.java:150)
  at com.sun.faces.facelets.compiler.TextInstruction.write(TextInstruction.java:85)
  at com.sun.faces.facelets.compiler.UIInstructions.encodeBegin(UIInstructions.java:82)
  at org.primefaces.renderkit.CoreRenderer.renderChild(CoreRenderer.java:67)
  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:875)
  at javax.faces.component.UIComponent.encodeAll(UIComponent.java:1764)
  at javax.faces.component.UIComponent.encodeAll(UIComponent.java:1760)
  at javax.faces.component.UIComponent.encodeAll(UIComponent.java:1760)
  at com.sun.faces.application.view.FaceletViewHandlingStrategy.renderView(FaceletViewHandlingStrategy.java:402)
  at com.sun.faces.application.view.MultiViewHandler.renderView(MultiViewHandler.java:131)
  at javax.faces.application.ViewHandlerWrapper.renderView(ViewHandlerWrapper.java:288)
  at com.sun.faces.lifecycle.RenderResponsePhase.execute(RenderResponsePhase.java:121)
  at com.sun.faces.lifecycle.Phase.doPhase(Phase.java:101)
  at com.sun.faces.lifecycle.LifecycleImpl.render(LifecycleImpl.java:139)
  at javax.faces.webapp.FacesServlet.service(FacesServlet.java:594)
  at org.apache.catalina.core.StandardWrapper.service(StandardWrapper.java:1550)
  at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:281)
  at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:175)
  at org.apache.catalina.core.StandardPipeline.doInvoke(StandardPipeline.java:655)
  at org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:595)
  at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:161)
  at org.apache.catalina.connector.CoyoteAdapter.doService(CoyoteAdapter.java:331)
  at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:231)
  at com.sun.enterprise.v3.services.impl.ContainerMapper$AdapterCallable.call(ContainerMapper.java:317)
  at com.sun.enterprise.v3.services.impl.ContainerMapper.service(ContainerMapper.java:195)
  at com.sun.grizzly.http.ProcessorTask.invokeAdapter(ProcessorTask.java:860)
  at com.sun.grizzly.http.ProcessorTask.doProcess(ProcessorTask.java:757)
  at com.sun.grizzly.http.ProcessorTask.process(ProcessorTask.java:1056)
  at com.sun.grizzly.http.DefaultProtocolFilter.execute(DefaultProtocolFilter.java:229)
  at com.sun.grizzly.DefaultProtocolChain.executeProtocolFilter(DefaultProtocolChain.java:137)
  at com.sun.grizzly.DefaultProtocolChain.execute(DefaultProtocolChain.java:104)
  at com.sun.grizzly.DefaultProtocolChain.execute(DefaultProtocolChain.java:90)
  at com.sun.grizzly.http.HttpProtocolChain.execute(HttpProtocolChain.java:79)
  at com.sun.grizzly.ProtocolChainContextTask.doCall(ProtocolChainContextTask.java:54)
  at com.sun.grizzly.SelectionKeyContextTask.call(SelectionKeyContextTask.java:59)
  at com.sun.grizzly.ContextTask.run(ContextTask.java:71)
  at com.sun.grizzly.util.AbstractThreadPool$Worker.doWork(AbstractThreadPool.java:532)
  at com.sun.grizzly.util.AbstractThreadPool$Worker.run(AbstractThreadPool.java:513)
   at java.lang.Thread.run(Thread.java:662)
      Caused by: com.sun.faces.spi.InjectionProviderException: com.sun.enterprise.container.common.spi.util.InjectionException: Exception attempting invoke lifecycle  method public void Beans.ParticipantBean.init()
  at org.glassfish.faces.integration.GlassFishInjectionProvider.invokePostConstruct(GlassFishInjectionProvider.java:231)
  at com.sun.faces.mgbean.BeanBuilder.invokePostConstruct(BeanBuilder.java:223)
  ... 55 more
    Caused by: com.sun.enterprise.container.common.spi.util.InjectionException: Exception attempting invoke lifecycle  method public void Beans.ParticipantBean.init()
  at org.glassfish.faces.integration.GlassFishInjectionProvider.invokeLifecycleMethod(GlassFishInjectionProvider.java:393)
  at org.glassfish.faces.integration.GlassFishInjectionProvider.invokePostConstruct(GlassFishInjectionProvider.java:306)
  at org.glassfish.faces.integration.GlassFishInjectionProvider.invokePostConstruct(GlassFishInjectionProvider.java:229)
  ... 56 more
      Caused by: java.security.PrivilegedActionException: java.lang.reflect.InvocationTargetException
  at java.security.AccessController.doPrivileged(Native Method)
  at org.glassfish.faces.integration.GlassFishInjectionProvider.invokeLifecycleMethod(GlassFishInjectionProvider.java:376)
  ... 58 more
      Caused by: java.lang.reflect.InvocationTargetException
  at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
  at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
  at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
  at java.lang.reflect.Method.invoke(Method.java:597)
  at org.glassfish.faces.integration.GlassFishInjectionProvider$2.run(GlassFishInjectionProvider.java:382)
  ... 60 more
    Caused by: java.lang.NullPointerException
  at Beans.ParticipantBean.init(ParticipantBean.java:408)
  ... 65 more
  </code></pre>
  
  <hr>
  
  <p>After Yamada UPDATE I obtain:</p>
  
  <pre><code>WARNING: #{auth.login()}: java.lang.NullPointerException
  javax.faces.FacesException: #{auth.login()}: java.lang.NullPointerException
  at com.sun.faces.application.ActionListenerImpl.processAction(ActionListenerImpl.java:118)
  at javax.faces.component.UICommand.broadcast(UICommand.java:315)
  at javax.faces.component.UIViewRoot.broadcastEvents(UIViewRoot.java:794)
  at javax.faces.component.UIViewRoot.processApplication(UIViewRoot.java:1259)
  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:118)
  at javax.faces.webapp.FacesServlet.service(FacesServlet.java:593)
  at org.apache.catalina.core.StandardWrapper.service(StandardWrapper.java:1550)
  at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:281)
  at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:175)
  at org.apache.catalina.core.StandardPipeline.doInvoke(StandardPipeline.java:655)
  at org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:595)
  at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:161)
  at org.apache.catalina.connector.CoyoteAdapter.doService(CoyoteAdapter.java:331)
  at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:231)
  at com.sun.enterprise.v3.services.impl.ContainerMapper$AdapterCallable.call(ContainerMapper.java:317)
  at com.sun.enterprise.v3.services.impl.ContainerMapper.service(ContainerMapper.java:195)
  at com.sun.grizzly.http.ProcessorTask.invokeAdapter(ProcessorTask.java:860)
  at com.sun.grizzly.http.ProcessorTask.doProcess(ProcessorTask.java:757)
  at com.sun.grizzly.http.ProcessorTask.process(ProcessorTask.java:1056)
  at com.sun.grizzly.http.DefaultProtocolFilter.execute(DefaultProtocolFilter.java:229)
  at com.sun.grizzly.DefaultProtocolChain.executeProtocolFilter(DefaultProtocolChain.java:137)
  at com.sun.grizzly.DefaultProtocolChain.execute(DefaultProtocolChain.java:104)
  at com.sun.grizzly.DefaultProtocolChain.execute(DefaultProtocolChain.java:90)
  at com.sun.grizzly.http.HttpProtocolChain.execute(HttpProtocolChain.java:79)
  at com.sun.grizzly.ProtocolChainContextTask.doCall(ProtocolChainContextTask.java:54)
  at com.sun.grizzly.SelectionKeyContextTask.call(SelectionKeyContextTask.java:59)
  at com.sun.grizzly.ContextTask.run(ContextTask.java:71)
  at com.sun.grizzly.util.AbstractThreadPool$Worker.doWork(AbstractThreadPool.java:532)
  at com.sun.grizzly.util.AbstractThreadPool$Worker.run(AbstractThreadPool.java:513)
  at java.lang.Thread.run(Thread.java:662)
      Caused by: javax.faces.el.EvaluationException: java.lang.NullPointerException
  at javax.faces.component.MethodBindingMethodExpressionAdapter.invoke(MethodBindingMethodExpressionAdapter.java:102)
  at com.sun.faces.application.ActionListenerImpl.processAction(ActionListenerImpl.java:102)
  ... 31 more
      Caused by: java.lang.NullPointerException
  at Beans.Auth.login(Auth.java:67)
  at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
  at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
  at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
  at java.lang.reflect.Method.invoke(Method.java:597)
  at javax.el.BeanELResolver.invokeMethod(BeanELResolver.java:779)
  at javax.el.BeanELResolver.invoke(BeanELResolver.java:528)
  at javax.el.CompositeELResolver.invoke(CompositeELResolver.java:257)
  at com.sun.el.parser.AstValue.invoke(AstValue.java:248)
  at com.sun.el.MethodExpressionImpl.invoke(MethodExpressionImpl.java:302)
  at com.sun.faces.facelets.el.TagMethodExpression.invoke(TagMethodExpression.java:105)
  at javax.faces.component.MethodBindingMethodExpressionAdapter.invoke(MethodBindingMethodExpressionAdapter.java:88)
  ... 32 more
  </code></pre>
  
  <p>The line 67 in Auth is findUser query</p>
  
  <pre><code>  public void login() throws IOException, ServletException {
      FacesContext context = FacesContext.getCurrentInstance();
      ExternalContext externalContext = context.getExternalContext();
      HttpServletRequest request = (HttpServletRequest) externalContext.getRequest();
  
      try {
          request.login(email, password);
          Participant user = userService.findUser(email, password);
          externalContext.getSessionMap().put("user", user);
          externalContext.redirect(originalURL);
      } catch (ServletException e) {
          // Handle unknown username/password in request.login().
          context.addMessage(null, new FacesMessage("Unknown login or wrong password"));
      }
  }
  </code></pre>
  
  <p>That works fine using RichFaces.</p>
  
  <p>The findUser method is in participanDAO class:</p>
  
  <pre><code>@Stateless
  @LocalBean
  @DeclareRoles({"SUPERADMINISTRATOR", "ADMINISTRATOR", "USER"})
  public class ParticipantDAO {
  
  /**
   * Creates a new instance of ParticipantDAO
   */
  public ParticipantDAO() {
  }
  @PersistenceContext
  private EntityManager em;
  @Resource
  SessionContext context;
  
  public Participant findUser(String email, String password) {
      password = DigestUtils.sha512Hex(password);
      TypedQuery&lt;Participant&gt; query = em.createNamedQuery(Participant.FIND_USER, Participant.class).setParameter("email", email).setParameter("password", password);
      List&lt;Participant&gt; results = query.getResultList();
      Participant user = null;
      if (!results.isEmpty()) {
          // ignores multiple results
          user = results.get(0);
      }
      return user;
  }
  </code></pre>