Frequently Asked Questions

Q: I get the following error when I try to access a JSP with a menu:

org.apache.jasper.JasperException: Could not obtain the menu repository

A: Check your struts-config.xml to make sure the plug-in settings are correct. They should be similar to the following:

<plug-in className="net.sf.navigator.menu.MenuPlugIn">
  <set-property property="menuConfig"
    value="/WEB-INF/menu-config.xml"/>
</plug-in>
<!-- The menuConfig property is an optional attribute.  It is set to
    /WEB-INF/menu-config.xml by default. -->

Q: How do I show/hide menus/items based on roles?

A: Add permissions="rolesAdapter" to your <menu:useMenuDisplayer> tag. Then in your menu-config.xml, put a comma-delimited list of roles that are allowed to view this menu or item. For more information, see the security model page.

Q: Can I use Struts Menu outside of a Struts Application?

A: 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>

NOTE: You'll need version 2.3+ if you want to remove struts.jar from your project. You can also configure the repository to be loaded by Spring. Just add the following to your context file:

<bean id="menu" class="net.sf.navigator.menu.MenuLoader">
  <property name="menuConfig">
    <value>/WEB-INF/menu-config.xml</value>
  </property>
</bean>
<!-- The menuConfig property is an optional attribute.  It is set to
    /WEB-INF/menu-config.xml by default. -->

Thanks to Dan Luputan for contributed code for the MenuLoader class.

I also added support for regular ol' ResourceBundles and, if you're using the EL tag - JSTL's ResourceBundle. Here's how it all works:

The EL tag defaults to JSTL's ResourceBundle if no "bundle" attribute is specified, and to Struts' MessageResources if that's not found. The regular tag defaults to Struts' MessageResources if no bundle is specified. All bad bundle attributes result in a log.error() rather than a JspException.

Q: How do I create a menu dynamically from a database?

A: The example app has a howto for dynamic menus.