Quicklinks

Tags menuItem - menuAction - menu - dynMenu

Introduction

Struts layout allows to create tree and drop down menu. The menu can be defined:

  • In the action class and store in the session context if it is going to be reused or modified
  • In the jsp with the menu tags
  • In an XML file

Defining the menu in an Action class

Struts layout menus reuse the framework written by Scott Sayles (which can be download here) so menus are defined in the Action class in the same way:

  • The menu must be made of MenuComponent
  • It must be put in the MenuRepository

LayoutUtils others two methods to access the repository: addMenu(MenuComponent) and getMenu(String menuName)

Defining the menu in the jsp file

The tag <layout:menuItem> can be used in a menu tag to define the menu to display.

Exemple:

<layout:menuItem key="menu.test.menu1" link="link1.html"/>
	<layout:menuItem key="menu.test.menu2">
		<layout:menuItem key="menu.test.item1" link="link2.html"/>
		<layout:menuItem key="menu.test.item2" link="link3.html"/>
	</layout:menuItem>	
	<layout:menuItem key="menu.test.menu3">
		<layout:menuItem key="menu.test.menu4">
			<layout:menuItem key="menu.test.item3" link="link4.html"/>
			<layout:menuItem key="menu.test.item4" link="link5.html"/>
		</layout:menuItem>
		<layout:menuItem key="menu.test.item5" link="link6.html"/>
	</layout:menuItem>
<layout:menuItem key="menu.test.menu5" link="link7.html"/>

This is how the menu are defined in the tree menu and drop down menu example belows.

Defining the menu in an XML file

As in Scott's framework

Displaying a tree menu

The tag <layout:menu> displays the specified menu as a tree menu. With IE5 or NS6 it is possible to expand / collapse a node. The state of the nodes are saved by cookies. Example:

<layout:menu styleClass="FORM" align="left">
	<layout:menuItem key="menu.test.menu1" link="link1.html"/>
	<layout:menuItem key="menu.test.menu2">
		<layout:menuItem key="menu.test.item1" link="link2.html"/>
		<layout:menuItem key="menu.test.item2" link="link3.html"/>
	</layout:menuItem>	
	<layout:menuItem key="menu.test.menu3">
		<layout:menuItem key="menu.test.menu4">
			<layout:menuItem key="menu.test.item3" link="link4.html"/>
			<layout:menuItem key="menu.test.item4" link="link5.html"/>
		</layout:menuItem>
		<layout:menuItem key="menu.test.item5" link="link6.html"/>
	</layout:menuItem>
	<layout:menuItem key="menu.test.menu5" link="link7.html"/>
</layout:menu>

Result:

Displaying a drop down menu

The tag <layout:dynMenu> displays the specified menu as a drop down menu. The javascript used is HierMenus 4.0.7 (http://www.webreference.com/dhtml/column50/) which works for nearly all browsers. Be careful that the version distributed with struts-layout is an old version. Newer versions have not been tested with struts-layout and require a licence. Here is an example of use:

<layout:dynMenu config="fr.improve.struts.webapp.layout.example.Mainmenu" left="100" top="150">
	<layout:menuItem key="menu.test.menu1" link="link1.html"/>
	<layout:menuItem key="menu.test.menu2">
		<layout:menuItem key="menu.test.item1" link="link2.html"/>
		<layout:menuItem key="menu.test.item2" link="link3.html"/>
	</layout:menuItem>	
	<layout:menuItem key="menu.test.menu3">
		<layout:menuItem key="menu.test.menu4">
			<layout:menuItem key="menu.test.item3" link="link4.html"/>
			<layout:menuItem key="menu.test.item4" link="link5.html"/>
		</layout:menuItem>
		<layout:menuItem key="menu.test.item5" link="link6.html"/>
	</layout:menuItem>
	<layout:menuItem key="menu.test.menu5" link="link7.html"/>
</layout:dynMenu>

And the result:

Content of the default dynMenu configuration file:

width=100
font_color="#D1D3FD"
mouseover_font_color="#FFFFFF"
background_color="#336699"
mouseover_background_color="#274465"
border_color="#000000"
separator_color="#000000"
top_is_permanent=1
top_is_horizontal=1
tree_is_horizontal=0
position_under=1
top_more_images_visible=0
tree_more_images_visible=1
evaluate_upon_tree_show="null"
evaluate_upon_tree_hide="null"

It is also possible to specify a default left and top position by setting the 'left_position' and 'top_position' properties.

Please report to HierMenus documentation for explanations about those properties.

It is possible to use different configuration files in function of the selected skin. For example if there are skin1.css and skin2.css, the file property names can be menu1_skin1.properties and menu1_skin2.properties. The value of the config attribute would be "menu1"

Note:

  • for now, struts-layout menu is compatible with Scott's menu model (repository & MenuComponent) but not with the menu displayer
  • Scott's Controler Servlet must be use in order to load the menu repository. If the menus are static and defined in the jsps, the normal Struts ActionServlet can de used
  • The javascript code used by the menus is included by the <layout:html> tag. If this tag is not used, config/javascript.js must be included before any use of the tree menu and config/HM_Loader.js must be included at the end of the page.

menuItem

Add an item to a menu.

This tag must be nested in another menuItem tag, or in a menu or dynMenu tag.

The key and the link attribute can be used to create a new menu item. It is also possible to retrieve a menu from Scott Sayles menu repository using the repository attribute.

Attributes

Attribute NameDescription
keyThe message key of the item
linkThe URL to forward to when this item is selected.
actionThe action to forward to when this item is selected.
nameName of the menu in the menu repository
styleitem css style

menuAction

This tag allows to add an action to a menu item.

This tags must be nested into a menuItem tag.

Attributes

Attribute NameDescription
keyThe message key of the item
linkThe URL to forward to when this item is selected.
targetThe target of the URL specified by the "link" attribute.

menu

Display a tree like menu

The content of the menu is specified by nested menuItem tags.

Attributes

Attribute NameDescription
bundleName of the bundle to use to retrive the item labels
styleClasscss class to use to display the menu

dynMenu

Display a drop down menu

The content of the menu is specified by nested menuItem tags.

Attribute

Attribute NameDescription
configName of the property file containing the configuration of the menu
includeScriptIf set to true, load HM_Loader.js (required to display the menu). Automatically done if the <layout:html> tag is used.
leftLeft position of the menu in pixel. A default value can be set in the property file.
topTop position of the menu in pixel. A default value can be set in the property file.