0 Replies Latest reply on Apr 30, 2008 3:21 AM by Viktor Rees

    Dynamic Menu read from database

    Viktor Rees Newbie

      Hallo,
      I posted already in the Seam forum without getting any answer yet:

      I want to create a menu dynamically by reading the menu items from database. The following code sniplet works quite well, except that the Menu collapses after each click on an menu item:

      <h:form>
       <rich:panelMenu mode="server" expandMode="server">
       <c:forEach items="#{appMenu.menuItems}" var="item">
       <rich:panelMenuGroup label="#{item.textValue}" >
       <c:forEach items="#{item.childs}" var="child">
       <rich:panelMenuItem submitMode="none">
       <s:link view="#{child.htmlLink}">
       <h:outputText value="#{child.textValue}"></h:outputText>
       </s:link>
       </rich:panelMenuItem>
       </c:forEach>
       </rich:panelMenuGroup>
       </c:forEach>
       </rich:panelMenu>
      </h:form>


      I tried several variations:

      instead of <s:link> i tried
      <h:outputLink value="#{child.htmlLink}">#{child.textValue}</h:outputLink>

      Result was an incorrect url: http://localhost:8080/AppUserList.xhtml instead of http://localhost:8080/AdaptTemplates/AppUserList.seam?cid=109

      instead of <s:link> i tried
      <rich:panelMenuItem label="#{child.textValue}" value="#{child.htmlLink}" submitMode="server">

      Result: Menu items get rendered as hidden input fields instead of Links to seam views.

      Using <ui:repeat> or <a4j:repeat> instead of <c:forEach> did not work at all, because they were not able handle the Set collections of the underlying EntityBean:
      @Entity
      @Table(name = "MENU_ITEM")
      public class MenuItem implements java.io.Serializable
      {
       private String id;
       private MenuItem parent;
       private String viewId;
       private String textValue;
       private String htmlLink;
       private Set<MenuItem> childs = new HashSet<MenuItem>(0);
       :
       @OneToMany(cascade = CascadeType.ALL, fetch = FetchType.LAZY, mappedBy = "parent")
       public Set<MenuItem> getChilds() {
       return this.childs;
       }
      
       public void setChilds(Set<MenuItem> childs) {
       this.childs = childs;
       }
      }


      Can somebody help?