treeview

The treeview tag displays a standard treeview component. Folders are open and close by DHTML. The treeview content can be defined by nesting menuItem tags, or by setting the name attribute to the value of the name of a menu in the menu repository

Cookies are used to remember which nodes in a treeview are open and close. This makes it impossible to put two different treeview defined by menuItem tags in the same page. However, it is possible to put several treeviews if they are defined in the menu repository.

If the treeview content is defined in the menu repository and if the content is big enough (more than 50 items by default) only the main nodes will be loaded. A server request will be made automatically to the struts-layout '/treeview' action to load the other nodes when required. The treeview action must be defined in struts-config.xml with the following attributes:

  • path="/treeview"
  • type="fr.improve.struts.taglib.layout.treeview.TreeviewAction"

If an image is associated to an item having subitems, clicking on the image will open or close all the subitems.

The treeview does not support the "action" attribute of the menuItem tag and of the MenuComponent objects.

Attributes

Attribute NameDescription
nameName of the menu in the menu repository to display as the treeview content
styleClass

Name of the css style class to use.

Unless the autoIncrement attribute is set to false, an integer representing the depth of the node is added after the value specified, allowing to use different classes for different node levels.

The styleClass attribute is used to in the TD tag used to generate the label of the node and in the A tag used to generate links.

autoIncrementIf set to false, the styleClass is not incremented each time a sub-node is displayed
expandedLevelsAtFirstDepth of menu to open at first

Examples

Treeview content defined in the jsp:

<layout:treeview>
	<layout:menuItem key="treeview.menu1" link="link1.html"/>
	<layout:menuItem key="treeview.menu2">
		<layout:menuItem key="treeview.menu2.submenu1">
			<layout:menuItem key="treeview.menu2.submenu1.item1" link="link2.html"/>
			<layout:menuItem key="treeview.menu2.submenu1.item1" link="link3.html"/>
		</layout:menuItem>
		<layout:menuItem key="treeview.menu2.submenu2" link="link3.html"/>
		<layout:menuItem key="treeview.menu2.submenu3" link="link4.html"/>		
	</layout:menuItem>
</layout:treeview>

Treeview content defined in the menu repository for a user. The treeview content is created in an action:

in the action:
public ActionForward perform(...) {
	...
	MenuComponent lc_menu1 = new MenuComponent();
	lc_menu1.setName("java");
	MenuComponent lc_menu11 = new MenuComponent();
	lc_menu11.setTitle("Java");
	MenuComponent lc_menu111 = new MenuComponent();
	lc_menu111.setTitle("Sun");
	lc_menu111.setLocation("http://java.sun.com");
	lc_menu11.addMenuComponent(lc_menu111);
	MenuComponent lc_menu112 = new MenuComponent();
	lc_menu111.setTitle("Eclipse");
	lc_menu111.setLocation("http://www.eclipse.org");
	lc_menu11.addMenuComponent(lc_menu112);
	lc_menu1.addMenuComponent(lc_menu11);
	...
	((MenuRepository)in_request.getSession().getAttribute(MenuRepository.MENU_REPOSITORY_KEY)).addMenu(lc_menu1);

in the jsp:
<layout:treeview name="java"/>

Runnable example

struts-layout comes with a runnable example of the treeview component including the previous examples. The example contains an action (fr.improve.struts.webapp.layout.example.treeview.TreevieAction) which defines a user treeview, and a jsp (/struts-layout/examples/treeview.jsp) displaying two treeviews. It can be run by invoking the /examples/treeview.do action.