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:-ADS_TO_REPLACE_1

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

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

pageEncoding="UTF-8"%>

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

"http://www.w3.org/TR/html4/loose.dtd">ADS_TO_REPLACE_3

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

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

<html>ADS_TO_REPLACE_4

<head>

<sx:head/>

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

<title>Example Tree Tag</title>

</head>

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

<div>

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

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

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

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

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

<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" />ADS_TO_REPLACE_9

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

</sx:treenode>

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

<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" />ADS_TO_REPLACE_11

</sx:treenode>

</sx:treenode>

</sx:treenode>ADS_TO_REPLACE_12

<sx:treenode label="Technical" >

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

</sx:treenode>ADS_TO_REPLACE_13

</sx:tree>

</div>

</body>ADS_TO_REPLACE_14

</html>

The Struts mapping file Struts.xml is as follows-

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

<!DOCTYPE struts PUBLICADS_TO_REPLACE_15

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

"http://struts.apache.org/dtds/struts-2.0.dtd">

<struts>ADS_TO_REPLACE_16

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

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

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

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

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

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

</action>

</package>

</struts>

The action class TreeTagAction.java is as follows.ADS_TO_REPLACE_19

package roseindia;

import com.opensymphony.xwork2.ActionSupport;

public class TreeTagAction extends ActionSupport{ADS_TO_REPLACE_20

public String execute() throws Exception {

return SUCCESS;

}ADS_TO_REPLACE_21

}

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

Output:-

ADS_TO_REPLACE_22

Download Select Source Code

Related Tags for Struts2.2.1 tree Tag Example:

Advertisements

Ads

Ads

 
Advertisement null

Ads