3 Replies Latest reply on Oct 24, 2009 9:09 AM by Nick Belaevski

    rich:panelMenu renderer NPE

    Greg Noe Newbie

      Hi All,

      Hopefully this is an easy one...

      I'm trying to build a rich:panelMenu object in my backing bean and then bind it to a rich:panelMenu tag in my page. For some reason I get a NullPointerException in the org.richfaces.renderkit.html.PanelMenuItemRenderer. Am I forgetting to do something? I've looked at the user guide and I couldn't figure out anything from there.

      I'm using Tomcat v6.0.20, JSF 1.2 and RichFaces-3.3.1.GA.

      Thanks!

      
      import org.richfaces.component.html.HtmlPanelMenu;
      import org.richfaces.component.html.HtmlPanelMenuGroup;
      import org.richfaces.component.html.HtmlPanelMenuItem;
      
      private HtmlPanelMenu trainingMenu;
      
      public final HtmlPanelMenu getTrainingMenu() {
      
       // We'll load the training menu only if necessary
       if (null == this.trainingMenu) {
      
       // Create a new instance of the HtmlPanelMenu
       this.trainingMenu = new HtmlPanelMenu();
      
       // Give it an ID
       this.trainingMenu.setId("trainingMenu");
      
       // Now add the stuff in the middle.
       List<EventGroup> tmpGroupList = new ArrayList<EventGroup>(DAOFactory.getFactory().getEventGroupDAO().findByEventType(E_EventType.ACCT_ED_TRAINING));
      
       // Iterate through event group as the salty, crunchy outer layer.
       for (EventGroup eg : tmpGroupList) {
      
       // Create the group.
       HtmlPanelMenuGroup pmg = new HtmlPanelMenuGroup();
      
       // Set the label for the group.
       pmg.setLabel(eg.getEventGroupTitle());
      
       // Iterate through the groups' members and add as a sweet, gooey caramel layer.
       for (Event ev : eg.getEventGroupMembers()) {
      
       // Make a new panel menu item
       HtmlPanelMenuItem pmi = new HtmlPanelMenuItem();
      
       // Set the item label
       pmi.setLabel(ev.getEventTitle());
      
       // Add the item to the parent group.
       pmg.getChildren().add(pmi);
      
       }
      
       // Done with the group members, now add the group to the panel menu
       this.trainingMenu.getChildren().add(pmg);
      
       }
      
       // Our sweet layer cake of menu-y goodness is now complete?
       }
      
       return this.trainingMenu;
      }
      
      
      <h:form id="frmAETGrp">
       <rich:panelMenu binding="#{acctEdDispBean.trainingMenu}"/>
      </h:form>
      


      The stack trace:

      Oct 22, 2009 4:22:07 PM com.sun.facelets.FaceletViewHandler handleRenderException
      SEVERE: Error Rendering View[/pages/home.xhtml]
      java.lang.NullPointerException
       at org.richfaces.renderkit.html.PanelMenuItemRenderer.isSelected(PanelMenuItemRenderer.java:261)
       at org.richfaces.renderkit.html.PanelMenuItemRenderer.getSelectedClass(PanelMenuItemRenderer.java:209)
       at org.richfaces.renderkit.html.HtmlPanelMenuItemRenderer.doEncodeBegin(HtmlPanelMenuItemRenderer.java:153)
       at org.richfaces.renderkit.html.HtmlPanelMenuItemRenderer.doEncodeBegin(HtmlPanelMenuItemRenderer.java:106)
       at org.ajax4jsf.renderkit.RendererBase.encodeBegin(RendererBase.java:100)
       at javax.faces.component.UIComponentBase.encodeBegin(UIComponentBase.java:801)
       at org.ajax4jsf.renderkit.RendererBase.renderChild(RendererBase.java:275)
       at org.ajax4jsf.renderkit.RendererBase.renderChildren(RendererBase.java:258)
       at org.richfaces.renderkit.html.HtmlPanelMenuGroupRenderer.doEncodeChildren(HtmlPanelMenuGroupRenderer.java:209)
       at org.richfaces.renderkit.html.HtmlPanelMenuGroupRenderer.doEncodeChildren(HtmlPanelMenuGroupRenderer.java:204)
       at org.ajax4jsf.renderkit.RendererBase.encodeChildren(RendererBase.java:120)
       at javax.faces.component.UIComponentBase.encodeChildren(UIComponentBase.java:825)
       at org.ajax4jsf.renderkit.RendererBase.renderChild(RendererBase.java:277)
       at org.richfaces.renderkit.html.PanelMenuRenderer.renderChildren(PanelMenuRenderer.java:543)
       at org.richfaces.renderkit.html.HtmlPanelMenuRenderer.doEncodeChildren(HtmlPanelMenuRenderer.java:261)
       at org.richfaces.renderkit.html.HtmlPanelMenuRenderer.doEncodeChildren(HtmlPanelMenuRenderer.java:256)
       at org.ajax4jsf.renderkit.RendererBase.encodeChildren(RendererBase.java:120)
       at javax.faces.component.UIComponentBase.encodeChildren(UIComponentBase.java:825)
       at com.sun.faces.renderkit.html_basic.HtmlBasicRenderer.encodeRecursive(HtmlBasicRenderer.java:234)
       at com.sun.faces.renderkit.html_basic.HtmlBasicRenderer.encodeRecursive(HtmlBasicRenderer.java:239)
       at com.sun.faces.renderkit.html_basic.HtmlBasicRenderer.encodeRecursive(HtmlBasicRenderer.java:239)
       at com.sun.faces.renderkit.html_basic.GridRenderer.renderRow(GridRenderer.java:178)
       at com.sun.faces.renderkit.html_basic.GridRenderer.encodeChildren(GridRenderer.java:126)
       at javax.faces.component.UIComponentBase.encodeChildren(UIComponentBase.java:825)
       at javax.faces.component.UIComponent.encodeAll(UIComponent.java:936)
       at javax.faces.component.UIComponent.encodeAll(UIComponent.java:942)
       at org.richfaces.renderkit.html.LayoutRenderer.renderLayout(LayoutRenderer.java:62)
       at org.richfaces.renderkit.html.LayoutRenderer.doEncodeChildren(LayoutRenderer.java:45)
       at org.ajax4jsf.renderkit.RendererBase.encodeChildren(RendererBase.java:120)
       at javax.faces.component.UIComponentBase.encodeChildren(UIComponentBase.java:825)
       at org.ajax4jsf.renderkit.RendererBase.renderChild(RendererBase.java:277)
       at org.ajax4jsf.renderkit.RendererBase.renderChildren(RendererBase.java:258)
       at org.ajax4jsf.renderkit.RendererBase.renderChild(RendererBase.java:279)
       at org.ajax4jsf.renderkit.RendererBase.renderChildren(RendererBase.java:258)
       at org.ajax4jsf.renderkit.html.AjaxOutputPanelRenderer.encodeChildren(AjaxOutputPanelRenderer.java:78)
       at javax.faces.component.UIComponentBase.encodeChildren(UIComponentBase.java:825)
       at org.ajax4jsf.renderkit.RendererBase.renderChild(RendererBase.java:277)
       at org.ajax4jsf.renderkit.AjaxChildrenRenderer.encodeAjaxComponent(AjaxChildrenRenderer.java:166)
       at org.ajax4jsf.renderkit.AjaxChildrenRenderer.encodeAjaxChildren(AjaxChildrenRenderer.java:83)
       at org.ajax4jsf.renderkit.AjaxChildrenRenderer.encodeAjaxComponent(AjaxChildrenRenderer.java:157)
       at org.ajax4jsf.renderkit.AjaxContainerRenderer.encodeAjax(AjaxContainerRenderer.java:123)
       at org.ajax4jsf.component.AjaxViewRoot.encodeAjax(AjaxViewRoot.java:677)
       at org.ajax4jsf.component.AjaxViewRoot.encodeChildren(AjaxViewRoot.java:548)
       at javax.faces.component.UIComponent.encodeAll(UIComponent.java:936)
       at com.sun.facelets.FaceletViewHandler.renderView(FaceletViewHandler.java:578)
       at org.ajax4jsf.application.ViewHandlerWrapper.renderView(ViewHandlerWrapper.java:100)
       at org.ajax4jsf.application.AjaxViewHandler.renderView(AjaxViewHandler.java:176)
       at com.sun.faces.lifecycle.RenderResponsePhase.execute(RenderResponsePhase.java:110)
       at com.sun.faces.lifecycle.Phase.doPhase(Phase.java:100)
       at com.sun.faces.lifecycle.LifecycleImpl.render(LifecycleImpl.java:139)
       at javax.faces.webapp.FacesServlet.service(FacesServlet.java:266)
       at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:290)
       at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
       at org.ajax4jsf.webapp.BaseFilter.doFilter(BaseFilter.java:510)
       at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:235)
       at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
       at org.ajax4jsf.webapp.BaseXMLFilter.doXmlFilter(BaseXMLFilter.java:178)
       at org.ajax4jsf.webapp.BaseFilter.handleRequest(BaseFilter.java:290)
       at org.ajax4jsf.webapp.BaseFilter.processUploadsAndHandleRequest(BaseFilter.java:368)
       at org.ajax4jsf.webapp.BaseFilter.doFilter(BaseFilter.java:495)
       at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:235)
       at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
       at com.canfieldassoc.java.web.filter.HibernateSessionRequestFilter.doFilter(HibernateSessionRequestFilter.java:58)
       at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:235)
       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.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:433)
       at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:128)
       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:293)
       at org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:849)
       at org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.process(Http11Protocol.java:583)
       at org.apache.tomcat.util.net.JIoEndpoint$Worker.run(JIoEndpoint.java:454)
       at java.lang.Thread.run(Thread.java:619)
      


        • 1. Re: rich:panelMenu renderer NPE
          Nick Belaevski Master

          Hi,

          Please set items' names.

          • 2. Re: rich:panelMenu renderer NPE
            Greg Noe Newbie

            Thanks. That did the trick. Did I miss something in the documentation that said that the name attribute is required?

            Now that the simple display works, I'm trying to make it so each HtmlPanelMenuItem that is created will be clickable, and when clicked an ajax request is made to update a field on the backing bean.

            I've tried creating an a4j:commandLink (AjaxCommandLink), but I cannot set it as a child of the rich:panelMenuItem (HtmlPanelMenuItem), because AjaxCommandLink does not implement UIComponent.

            Also, I can't create a4j:actionParams and add those as children of an a4j:commandLink.

            I've tried creating and adding UIParameters to the HtmlPanelMenuItem along with configuring the menu item to do the work, but still no luck.

            Again, am I missing something obvious?

            • 3. Re: rich:panelMenu renderer NPE
              Nick Belaevski Master

              Hi,

              Use

              <rich:panelMenuItem mode="ajax" ...>


              AjaxCommandLink is a tag, you should use HtmlAjaxCommandLink.