Home Struts Struts Struts2.2.1 Tags Struts2.2.1 tree Tag Example

Ask Questions?

View Latest Questions


 
 

Struts2.2.1 tree Tag Example
Posted on: January 20, 2011 at 12:00 AM
Advertisement
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"

pageEncoding="UTF-8"%>

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

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

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

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

<html>

<head>

<sx:head/>

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

<title>Example Tree Tag</title>

</head>

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

<div>

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

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

</sx:treenode>

</sx:treenode>

<sx:treenode label="Technical" >

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

</sx:treenode>

</sx:tree>

</div>

</body>

</html>

The Struts mapping file Struts.xml is as follows-

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

<!DOCTYPE struts PUBLIC

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

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

<struts>

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

</action>

</package>

</struts>

The action class TreeTagAction.java 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-

Output:-

Download Select Source Code

Related Tags for Struts2.2.1 tree Tag Example:


DMCA.com