With the Tree tag it is possible to generate a navigation tree starting from a model.
The following steps are required to setup the tags and get started witht he first example:
Import the FreeHEP Web Utils as described here.
Include the tags in any jsp page you want to use them by adding
<%@taglib prefix="tree" uri="http://java.freehep.org/tree-taglib" %>
The tree icons are generated via a servlet to allow users to modify the look of the tree. If no icons are provided by the user the default ones will be picked up. To add the servlet add the following lines to your WEB-INF/web.xml file.
<servlet> <servlet-name>fhicon</servlet-name> <servlet-class>org.freehep.webutil.tree.IconServlet</servlet-class> <load-on-startup>1</load-on-startup> </servlet> <servlet-mapping> <servlet-name>fhicon</servlet-name> <url-pattern>/icon.jsp</url-pattern> </servlet-mapping>
The model used to create the tree is the root node containing the tree structure. The nodes in the tree must implement the org.freehep.webutil.tree.TreeNode interface for which we provide a default implementation; please refer to the api documentation.
The following example shows how to create a simple model in a JSP environment:
<% org.freehep.webutil.tree.DefaultTreeNode root = new org.freehep.webutil.tree.DefaultTreeNode("root"); root.createNodeAtPath("A"); root.createNodeAtPath("A/a"); root.createNodeAtPath("/A/B"); root.createNodeAtPath("/A/B/b/"); root.createNodeAtPath("/A/B/c"); session.setAttribute("root", root); %>
Once the model has been created the navigation tree is generated with the following:
<tree:tree model="${root}"/>
By default the tree is using icons distributed by default with the code. It is possible to customizing the look of the tree by providing your own icons. Do do so you can specify the location of your icons in the WEB-INF/classes/freehepWebapp.properties file. The properties related to the icons are:
Name |
freehep.tree.images.doc |
freehep.tree.images.folderclosed |
freehep.tree.images.folderopen |