Suggestion for Menu

1 message Options
Embed this post
Permalink
WarnerJan Veldhuis

Suggestion for Menu

Reply Threaded More More options
Print post
Permalink
Some javascript/style in this post has been disabled (why?)
Hello Bob et al. :)

FYI: I modified the Menu.java code in such a way that you can create menuitems based on ActionLinks. I saw the menu example, where the logout item was added manually, which does not integrate the item in the menu nicely.

Here's an example menu.xml which incorporates an ActionLink
<menu>
    <menu label="Home">
        <menu separator="true" roles="SU, DU, VU, WU"/>
        <menu label="logoffLink" actionlink="true" roles="SU, DU, VU, WU"/>
    </menu>
</menu>

The label logoffLink corresponds to an ActionLink I added in my model in my TemplatePage class:

ActionLink logoffLink = new ActionLink("logoffLink", getMessage("logoffLink"), this, "onLogOff");
addControl(logoffLink);
getModel().put("menu", Menu.getRootMenu() );


The macro that renders the menu is modified slightly:
             #foreach ($subMenu in $topMenu.children)
               #if ($subMenu.isUserInRoles())
                 ><li>
                 #if ( $subMenu.isActionLink() )
                    #evaluate($subMenu)
                 #else
                    $subMenu
                 #end

                    </li
               #end
             #end

With Menu#actionLink being true, the Menu will render the label as $label, making is suitable for the Velocity #evaluate( ) function.

If you want the code you can probably do it yourself now, but I'm happy to submit it somewhere.

Cheers,

WarnerJan