0 Replies Latest reply on Jul 18, 2008 3:17 AM by Michael Trompertz

    How to create dynamic PanelMenu

    Michael Trompertz Newbie

      Hello
      I want to create a PanelMenu with groups and items with data from a database.
      When calling the page I got an exception:

      java.lang.ClassCastException: com.sun.facelets.component.UIRepeat
      at org.richfaces.renderkit.html.PanelMenuRenderer.insertScript(PanelMenuRenderer.java:142)
      at org.richfaces.renderkit.html.HtmlPanelMenuRenderer.doEncodeEnd(HtmlPanelMenuRenderer.java:261)
      at org.richfaces.renderkit.html.HtmlPanelMenuRenderer.doEncodeEnd(HtmlPanelMenuRenderer.java:272)
      at org.ajax4jsf.renderkit.RendererBase.encodeEnd(RendererBase.java:135)
      at javax.faces.component.UIComponentBase.encodeEnd(UIComponentBase.java:836)
      at javax.faces.component.UIComponent.encodeAll(UIComponent.java:896)
      at com.sun.facelets.component.RepeatRenderer.encodeChildren(RepeatRenderer.java:50)
      at com.sun.facelets.component.UIRepeat.process(UIRepeat.java:357)
      ...

      I assume that PanelMenu allows only PanelMenuGroup/PanelMenuItem as child. What can I do (I tried with for each, but the data is loaded to late, so my MenuItems are empty.
      Tried with 3.2.1GA an 3.2.2 nightly, both failed.

      Bean:
      @Name("menuaction")
      @Scope(ScopeType.SESSION)
      public class MenuAction {

      @In
      private Session seam5Datasource;

      @DataModel
      private List topLevelMenuList = new ArrayList();

      @DataModelSelection("topLevelMenuList")
      @Out(required = false)
      @In(required = false)
      private TopLevelMenu topLevelMenu;

      @Factory("topLevelMenuList")
      public void getTopLevelMenus() {
      String queryString = "select t from TopLevelMenu t order by sortOrder, text" ;
      topLevelMenuList = seam5Datasource.createQuery(queryString).list();
      }

      public Collection getMenuCollection()
      {
      return topLevelMenu == null ? null : topLevelMenu.getMenus();
      }

      XHTML-File:
      <ui:repeat value="${topLevelMenuList}" var="tlm">
      <rich:panelMenu mode="server">
      <rich:panelMenuGroup label="${tlm.text}" action="xyz">
      <ui:repeat value="${menuaction.getMenuCollection()}" var="m">
      <rich:panelMenuItem label="${m.menuText}" reRender="test"
      action="${m.menuLink}">
      </rich:panelMenuItem>
      </ui:repeat>
      </rich:panelMenuGroup>
      </rich:panelMenu>
      </ui:repeat>

      Michael