Struts layout allows to create tree and drop down menu. The menu can be defined:
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:
LayoutUtils others two methods to access the repository: addMenu(MenuComponent) and getMenu(String menuName)
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.
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:

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:
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.
This tag allows to add an action to a menu item.
This tags must be nested into a menuItem tag.
Display a drop down menu
The content of the menu is specified by nested menuItem tags.
| Attribute Name | Description |
|---|---|
| config | Name of the property file containing the configuration of the menu |
| includeScript | If set to true, load HM_Loader.js (required to display the menu). Automatically done if the <layout:html> tag is used. |
| left | Left position of the menu in pixel. A default value can be set in the property file. |
| top | Top position of the menu in pixel. A default value can be set in the property file. |