To upgrade from Struts Menu 1.x to Struts Menu 2.x, you need to change a few things:
<%@ taglib uri="http://struts-menu.sf.net/tag" prefix="menu" %>
<plug-in className="net.sf.navigator.menu.MenuPlugIn">
<Displayer name="Simple" type="net.sf.navigator.displayer.SimpleMenuDisplayer"/>
Struts Menu can be easily integrated into your Struts application. Here are the steps you need to take to integrate this tag library.
Copy struts-menu.jar into your WEB-INF/lib directory. Add the plug-in settings to your struts-config.xml file.
<plug-in className="net.sf.navigator.menu.MenuPlugIn"> <set-property property="menuConfig" value="/WEB-INF/menu-config.xml"/> <!-- Default settings --> </plug-in>
For Struts Menu 2.1+, you can put Jakarta's Standard Tag Library JAR in your WEB-INF/lib directory if you want to resolve EL expressions in menu-config.xml.
<Menu name="contactMenu" title="Contact" location="?Contact"> <Item name="email" title="E-Mail" location="?EMail"/> <Item name="phone" title="Phone" location="?Phone"/> </Menu>
<%@ taglib uri="http://struts-menu.sf.net/tag" prefix="menu" %>
<menu:useMenuDisplayer name="TabbedMenu" bundle="org.apache.struts.action.MESSAGE"> <menu:displayMenu name="Home"/> <menu:displayMenu name="About"/> </menu:useMenuDisplayer>
The name="TabbedMenu" is defined in menu-config.xml towards the top:
<Displayer name="TabbedMenu" type="net.sf.navigator.displayer.TabbedMenuDisplayer"/>
To use a customizeable Velocity template to render your menu, you will need to integrate Velocity into your webapp. To do this, perform the following steps:
<Displayer name="Velocity" type="net.sf.navigator.displayer.VelocityMenuDisplayer"/>
There are many examples of using the Velocity displayer in the sample application as well as AppFuse. The example application will show you the CSS, JavaScript and image files you will need for each menu. Below are links to the Velocity templates currently available in Struts Menu.
All the relevant files you might need are available on this site:
For more information on hiding/displaying menu items based on roles, see the FAQs.
In version 2.2+, the Menu Repository can now be loaded using a MenuContextListener:
<!-- - Loads the menu-config.xml for struts-menu at startup, - by default from "/WEB-INF/menu-config.xml". - To override this, add a context-param named "menuConfigLocation" - web.xml file. --> <listener> <listener-class>net.sf.navigator.menu.MenuContextListener</listener-class> </listener>
Or if you're using Spring, it's even easier. Just add the following to your applicationContext.xml file:
<bean id="menu" class="net.sf.navigator.menu.MenuLoader"> <property name="menuConfig" value="/WEB-INF/menu-config.xml"/> <-- default and optional --> </bean>
Thanks to Dan Luputan for contributed code for the MenuLoader class.
To build this project from source, perform the following steps:
To deploy the struts-menu example application, do the following:
If you'd like to use Eclipse to build this project, see the Developer Guide Developer Guide.