Use of the styleClass attribute

Use of the styleClass attribute
What is the styleClass attribute used for ?

The styleClass attribute is used to set the css class of the TD and A elements of a node. The TD element contains the name of the node, and the A element the link associated to the node. Be careful that unless explicity not asked to (see the autoIncrement attribute), stuts-layout automatically adds an integer specifying the depth of the node at the end of the styleClass.

			<layout:treeview styleClass="TREEVIEWCLASS"/>
			

will generate something like this for items of depth 1

			<td class="TREEVIEWCLASS1">Item 1 name</td>
			<td class="TREEVIEWCLASS1">Item 2 name</td>
			

Items of depth 2 will have:

			<td class="TREEVIEWCLASS2">Subitem 1 name</td>
			<td class="TREEVIEWCLASS2">Subitem 2 name</td>
			

If there is a link for the item, you'll have something like this:

			<td class="TREEVIEWCLASS1"><a href="some url" class="TREEVIEWCLASS1">Item 1 name</a></td>
			<td class="TREEVIEWCLASS1"><a href="some url 2" class="TREEVIEWCLASS1">Item 2 name</a></td>
			

and for sub nodes:

			<td class="TREEVIEWCLASS2"><a href="some url 3" class="TREEVIEWCLASS2">Subitem 1 name</a></td>
			<td class="TREEVIEWCLASS2"><a href="some url 4" class="TREEVIEWCLASS2">Subitem 2 name</a></td>
		
How can I use different styles for different node levels ?
stuts-layout automatically adds an integer specifying the depth of the node at the end of the styleClass.

Open and close node

Open and close node
How can I open a tree defined in a JSP when first viewing it ?
You can use the "expandedLevelsAtFirst" attribute of the treeview tag to set the depth of the nodes to open at first.
How can I open or close a node programatically ?
If you create your tree in a Struts action, using the MenuComponent class, you can use the setOpen(boolean) method to open or close a node. This requires the fr.improve.struts.taglib.layout.workflow.LayoutRequestProcessor to be configured in the struts-config.xml file.

Javascript

Javascript
I got a Javascript error and nothing happen when I click on a node, what happens ?

Your page is probably missing the treeview javascript code. To include this code, you need to put a <layout:html> or <layout:skin includeScript="true"> in the page.

Example :

		<html>
			<%@ taglib uri="http://struts.improve-technologies.com/layout" prefix="layout" %>
			<head>
				<layout:skin includeScript="true"/>
				...
			</head>
			<body>
				...
				<layout:treeview .../>
				...
			</body>
		</html>