Struts2.2.1 tree Tag Example
Posted on: January 20, 2011 at 12:00 AM
In this Tutorial, we will discuss about the tree tag in struts2.2.1.

Struts2.2.1 tree Tag Example

The tree & treenode tag  render a tree node within a tree widget with AJAX support.The tree & treenode of the two combinations are used depending on the requirement like the tree is needed to be constructed dynamically or statically.

The following Example will shows how to implement the tree & treenode tag in the Struts2.2.1 --

Directory Structure of the program:-

First we create a JSP file named TreeTag.jsp as follows.

<%@ page language="java" contentType="text/html; charset=UTF-8"


<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"


<%@taglib prefix="s" uri="/struts-tags"%>

<%@ taglib prefix="sx" uri="/struts-dojo-tags"%>




<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">

<title>Example Tree Tag</title>


<body><h1>Example tree & treenode Tag</h1>


<sx:tree id="books" label="Books" title="test" >

<sx:treenode label="Programing books" title="test">

<sx:treenode label="Java" title="test">

<sx:treenode id="Thread-Books" label="Core-Java" >

<sx:treenode id="Thread-Books" label="Java in Action" />

<sx:treenode id="Thread-Books" label="Core-Java Essentials" />

<sx:treenode id="Thread-Books" label="Head first Java" />

<sx:treenode id="Thread-Books" label="Multi-threading" />

<sx:treenode id="Thread-Books" label="Networking" />


<sx:treenode label="J2EE" title="test1">

<sx:treenode id="Thread-Books" label="JSP in Action" />

<sx:treenode id="Thread-Books" label="Core-JSP-Servlet" />

<sx:treenode id="Thread-Books" label="Advance JSP-Servlet" />




<sx:treenode label="Technical" >

<sx:treenode label="Science books"></sx:treenode>






The Struts mapping file Struts.xml is as follows-

<?xml version="1.0" encoding="UTF-8"?>


"-//Apache Software Foundation//DTD Struts Configuration 2.0//EN"



<constant name="struts.enable.DynamicMethodInvocation" value="false" />

<constant name="struts.devMode" value="false" />

<constant name="struts.custom.i18n.resources" value="ApplicationResources" />

<package name="roseindia" extends="struts-default" namespace="/">

<action name="TreeTag" class="roseindia.TreeTagAction">

<result name="success">/TreeTag.jsp</result>




The action class is as follows.

package roseindia;

import com.opensymphony.xwork2.ActionSupport;

public class TreeTagAction extends ActionSupport{

public String execute() throws Exception {

return SUCCESS;



This Program produces output on the basis of the tree & treenode Tag  evaluation, This  give the output as-


Download Select Source Code

Related Tags for Struts2.2.1 tree Tag Example:




Advertisement null