How to display just the child menu items in appfuse

1.3k Views Asked by At

(I think this is coming from appfuse, anyway. I'm not always clear on what's part of which framework still.)

I've got this in my menu-config.xml:

<?xml version="1.0" encoding="UTF-8"?>
<MenuConfig>
    <Displayers>
        <Displayer name="Velocity" type="net.sf.navigator.displayer.VelocityMenuDisplayer"/>
    </Displayers>
    <Menus>
        <Menu name="MainMenu" title="mainMenu.title" page="/mainmenu">
            <Item name="Foo" title="menu.foo" page="/foo"/>
            <Item name="Bar" title="menu.bar" page="/bar"/>
            <Item name="Baz" title="menu.baz" page="/baz"/>
        </Menu>
        <Menu name="OtherMenu" title="otherMenu.title" page="/othermenu">
            <Item name="Squee" title="menu.squee" page="/squee"/>
            <Item name="Lorem" title="menu.lorem" page="/lorem"/>
        </Menu>
        <Menu name="UserMenu" title="menu.user" description="User Menu" page="mainmenu.editprofile" roles="ROLE_ADMIN,ROLE_USER"/>
        <Menu name="Logout" title="user.logout" page="/logout" roles="ROLE_ADMIN,ROLE_USER"/>
    </Menus>
</MenuConfig>

For my main navigation, I've got this in my menu.jsp:

<%@ include file="/common/taglibs.jsp"%>

<menu:useMenuDisplayer name="Velocity" config="cssHorizontalMenu.vm" permissions="rolesAdapter">
<ul class="tabs menuList">
    <menu:displayMenu name="MainMenu"/>
</ul>
</menu:useMenuDisplayer>

That pretty much works, except I'm getting both the top level and child items of the main menu in my output. I actually only want the child items, i.e.:

<ul>
  <li>Foo</li>
  <li>Bar</li>
  <li>Baz</li>
</ul>

not

<ul>
   <li>Main Menu</li>
   <li>
    <ul>
      <li>Foo</li>
      <li>Bar</li>
      <li>Baz</li>
    </ul>
  </li>
</ul>

Is there some way to do that?

1

There are 1 best solutions below

0
On

So late, but I hope can help to somebody...

Do you need look into your cssHorizontalMenu.vm, it does the work of generation of the HTML output. If do you have a .vm

Maybe you have something like this:

#macro( displayCssMenu $menu )
  #if ($displayer.isAllowed($menu))
    #set ($count = $count + 1)
    ## set menu title
    #set ($title = $displayer.getMessage($menu.title))
    #if (!$menu.url) #set ($url="javascript:void(0)") #else #set ($url=$menu.url) #end

    ## create a single menu item
    #set ($itemClass = "")
    #if (!$menu.parent)
        #set ($itemClass = "mainItem")
    #end
    #set ($img = "")
    #if ($menu.image)
        #set ($img = "<img alt='$menu.image' class='icon setImageMenu $menu.image'/>")
    #end
    #if ($menu.components.size() == 0)
        #if ($count == $renderedChildren)
          <li class="last">
        #else
          <li>
        #end
        #if ($menu.name == $currentMenu)
          <a href="$url" title="$title" class="current $itemClass" #if($menu.target)target="$menu.target" #end#if($menu.width)style="width: ${menu.width}px"#end>$img ${title}</a>
        #else
          <a href="$url" title="$title" class="$itemClass" #if($menu.target)target="$menu.target" #end#if($menu.width)style="width: ${menu.width}px"#end>$img ${title}</a>
        #end
    #else ## create multiple menu items in a menu
        #if ($menu.components.size() > 0)
            #set ($hasViewableChildren = false)
            #set ($renderedChildren = 0)
            #foreach ($menuIt in $menu.components)
                #if ($displayer.isAllowed($menuIt))
                    #set($hasViewableChildren = true)
                    #set($renderedChildren = $renderedChildren + 1)
                #end
            #end
        #end

        <li#if ($hasViewableChildren) class="menubar"#end>
          <a href="$url" title="$title" #if ($menu.name == $currentMenu) class="current $itemClass" #else class="$itemClass" #end#if($menu.target)target="$menu.target" #end#if($menu.width)style="width: ${menu.width}px"#end>$img ${title}</a>
    #end

    #if ($menu.components.size() > 0)
        #if ($hasViewableChildren) 
          <ul> 
        #end

        #set ($count = 0)
        #foreach ($menuIt in $menu.components)
            #displayCssMenu($menuIt)
        #end

        #if ($hasViewableChildren && ($count == $renderedChildren))
          </li>
        #else
          </ul>
          #if ($count > $renderedChildren) 
          </li>
          #end
        #end
    #else
      </li>
      #if ($count == $menu.parent.components.size())
      </ul>
      #end
    #end
  #end
#end

#displayCssMenu($menu)

then you can try to do this... (look for the #if ($menu.parent))

#if ($menu.components.size() == 0 && $menu.parent)
        #if ($count == $renderedChildren)
          <li class="last">
        #else
          <li>
        #end
        bla.. bla...

        bla.. bla...
    #end

    #if ($menu.components.size() > 0)
        #if ($hasViewableChildren) 
          <ul> 
        #end

        bla.. bla...
    #else
        #if ($menu.parent)
             </li>
        #end
      #if ($count == $menu.parent.components.size())
          </ul>
      #end
    #end

this prevent to print the LI A elements for the parent menu, and only prints the items elements...