1 Reply Latest reply on Jun 15, 2009 3:49 PM by Ryan de Laplante

    Please help dynamically build HtmlPanelMenu

    Ryan de Laplante Newbie

      Hi,

      I'm having difficulty dynamically building a RichFaces HtmlPanelMenu from code. I've seen other people report the exception I'm having and their solution is to make sure everything has an id, but that doesn't work for me. Here is what the facelets tag looks like:

      <rich:panelMenu binding="#{menus.menu}"/>



      The following class is a session scoped MBean called "menu":


      public class MenusMBean {
      
       public HtmlPanelMenu getMenu() {
       HtmlPanelMenu menu = new HtmlPanelMenu();
       menu.setId("menu1");
      
       HtmlPanelMenuGroup group1 = new HtmlPanelMenuGroup();
       group1.setLabel("menugroup1");
       group1.setName("menugroup1");
       group1.setId("menugroup1");
      
       HtmlPanelMenuItem item1 = new HtmlPanelMenuItem();
       item1.setLabel("menu1item1");
       item1.setValue("menu1item1");
       item1.setId("menu1item1");
      
       group1.getChildren().add(item1);
       menu.getChildren().add(group1);
      
       menu.setSelectedChild("menu1item1");
      
       return menu;
       }
      
       public void setMenu(HtmlPanelMenu menu) {
      
       }
      }
      

      When I navigate to the page that contains the above mentioned facelets tag, I get this exception:

      java.lang.NullPointerException
       at org.richfaces.renderkit.html.PanelMenuGroupRenderer.isSelected(PanelMenuGroupRenderer.java:318)
       at org.richfaces.renderkit.html.PanelMenuGroupRenderer.getSelectedClass(PanelMenuGroupRenderer.java:252)
       at org.richfaces.renderkit.html.HtmlPanelMenuGroupRenderer.doEncodeBegin(HtmlPanelMenuGroupRenderer.java:134)
       at org.richfaces.renderkit.html.HtmlPanelMenuGroupRenderer.doEncodeBegin(HtmlPanelMenuGroupRenderer.java:106)
       at org.ajax4jsf.renderkit.RendererBase.encodeBegin(RendererBase.java:101)
       at javax.faces.component.UIComponentBase.encodeBegin(UIComponentBase.java:788)
       at org.ajax4jsf.renderkit.RendererBase.renderChild(RendererBase.java:280)
       at org.richfaces.renderkit.html.PanelMenuRenderer.renderChildren(PanelMenuRenderer.java:543)
       at org.richfaces.renderkit.html.HtmlPanelMenuRenderer.doEncodeChildren(HtmlPanelMenuRenderer.java:244)
       at org.richfaces.renderkit.html.HtmlPanelMenuRenderer.doEncodeChildren(HtmlPanelMenuRenderer.java:239)
       at org.ajax4jsf.renderkit.RendererBase.encodeChildren(RendererBase.java:121)
       at javax.faces.component.UIComponentBase.encodeChildren(UIComponentBase.java:812)
      ...



      I've looked a bit at RichFaces source code (from commit logs linked to from google). I see the source code has many places where it throws a NullPointerException with no error message indicating what the problem is.

      Can someone please help?


      Thanks,
      Ryan