<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>Code Pencil &#187; ajax</title>
	<atom:link href="http://www.codepencil.com/index.php/category/ajax/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.codepencil.com</link>
	<description>Manu Mahajan`s blog</description>
	<lastBuildDate>Tue, 14 Apr 2009 16:15:38 +0000</lastBuildDate>
	<generator>http://wordpress.org/?v=2.8.6</generator>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
			<item>
		<title>Struts2 &#8211; Dojo Dynamic Tree</title>
		<link>http://www.codepencil.com/index.php/struts2-dojo-dynamic-tree/</link>
		<comments>http://www.codepencil.com/index.php/struts2-dojo-dynamic-tree/#comments</comments>
		<pubDate>Wed, 19 Sep 2007 06:50:22 +0000</pubDate>
		<dc:creator>Manu Mahajan</dc:creator>
				<category><![CDATA[ajax]]></category>
		<category><![CDATA[code]]></category>
		<category><![CDATA[dojo]]></category>
		<category><![CDATA[java]]></category>
		<category><![CDATA[struts2]]></category>

		<guid isPermaLink="false">http://www.codepencil.com/?p=7</guid>
		<description><![CDATA[In my previous attempt at creating a tree using struts2 and dojo, I stumbled upon a roadblock. As the size of the tree grew larger the performance started deteriorating. Our tree had 500 nodes and it took about 1min 20sec for the tree to render in internet explorer 6!
So the need was to create a [...]]]></description>
			<content:encoded><![CDATA[<p>In my <a href="?p=4">previous attempt</a> at creating a tree using struts2 and dojo, I stumbled upon a roadblock. As the size of the tree grew larger the performance started deteriorating. Our tree had 500 nodes and it took about <strong>1min 20sec</strong> for the tree to render in internet explorer 6!</p>
<p>So the need was to create a dynamic tree which would load nodes as and when required.</p>
<p><span id="more-7"></span></p>
<p>I managed to create a simple application based on the struts-blank application which demonstrates how this can be achieved. I am pasting the code here so that it can help other people who want to achieve this using struts 2.0.9.</p>
<h3>The JSP Code</h3>
<p>I start by creating a <em>dynamicTree.jsp</em> file which will paint the tree. </p>
<p>I will create a tree with one root node in my html page and when that node is expanded its sub nodes will be loaded. It is possible to load a tree with any number of nodes in the beginning but I am going to keep this example simple so I am starting with a single node.</p>
<p>For painting the tree tag and the root node I <em>could not</em> use the struts2 taglib as I need to use attributes for dojo widgets that are not supported by struts2. Like the attribute <em>&#8216;controller&#8217;</em> is not supported by the tree tag and <em>&#8216;isFolder&#8217;</em> is not supported by the <em>treeNode</em> tag. The next version (2.1.0) has this fixed but the latest stable version at the moment is 2.0.9.</p>
<p>Here is what my jsp looks like</p>

<div class="wp_syntax"><div class="code"><pre class="xml"><span style="color: #009900;"><span style="font-weight: bold; color: black;">&lt;</span>%@ page <span style="color: #000066;">contentType</span>=<span style="color: #ff0000;">&quot;text/html; charset=UTF-8&quot;</span> %<span style="font-weight: bold; color: black;">&gt;</span></span>
<span style="color: #009900;"><span style="font-weight: bold; color: black;">&lt;</span>%@ taglib <span style="color: #000066;">prefix</span>=<span style="color: #ff0000;">&quot;s&quot;</span> <span style="color: #000066;">uri</span>=<span style="color: #ff0000;">&quot;/struts-tags&quot;</span> %<span style="font-weight: bold; color: black;">&gt;</span></span>
<span style="color: #009900;"><span style="font-weight: bold; color: black;">&lt;html<span style="font-weight: bold; color: black;">&gt;</span></span></span>
<span style="color: #009900;"><span style="font-weight: bold; color: black;">&lt;head<span style="font-weight: bold; color: black;">&gt;</span></span></span>
  <span style="color: #009900;"><span style="font-weight: bold; color: black;">&lt;s:head</span> <span style="color: #000066;">theme</span>=<span style="color: #ff0000;">&quot;ajax&quot;</span> <span style="color: #000066;">debug</span>=<span style="color: #ff0000;">&quot;true&quot;</span><span style="font-weight: bold; color: black;">/&gt;</span></span>
<span style="color: #009900;"><span style="font-weight: bold; color: black;">&lt;script<span style="font-weight: bold; color: black;">&gt;</span></span></span>
&nbsp;
   //Load the tree controller and extensions
  dojo.require(&quot;dojo.widget.TreeLoadingController&quot;);
  dojo.require(&quot;dojo.widget.TreeControllerExtension&quot;);
&nbsp;
  dojo.addOnLoad(function() {
    //Add the extensions to the controller
    dojo.lang.mixin(dojo.widget.byId('treeController'), dojo.widget.TreeControllerExtension.prototype);
  });
&nbsp;
}
<span style="color: #009900;"><span style="font-weight: bold; color: black;">&lt;/script<span style="font-weight: bold; color: black;">&gt;</span></span></span>
&nbsp;
<span style="color: #009900;"><span style="font-weight: bold; color: black;">&lt;/head<span style="font-weight: bold; color: black;">&gt;</span></span></span>
<span style="color: #009900;"><span style="font-weight: bold; color: black;">&lt;body<span style="font-weight: bold; color: black;">&gt;</span></span></span>
&nbsp;
<span style="color: #009900;"><span style="font-weight: bold; color: black;">&lt;div</span> <span style="color: #000066;">dojoType</span>=<span style="color: #ff0000;">&quot;TreeLoadingController&quot;</span>
  <span style="color: #000066;">widgetId</span>=<span style="color: #ff0000;">&quot;treeController&quot;</span>
  <span style="color: #000066;">RPCUrl</span>=<span style="color: #ff0000;">&quot;tree_gettreenodes.action&quot;</span><span style="font-weight: bold; color: black;">&gt;</span></span><span style="color: #009900;"><span style="font-weight: bold; color: black;">&lt;/div<span style="font-weight: bold; color: black;">&gt;</span></span></span>
&nbsp;
<span style="color: #009900;"><span style="font-weight: bold; color: black;">&lt;dojo:TreeSelector</span> <span style="color: #000066;">widgetId</span>=<span style="color: #ff0000;">&quot;treeSelector_contentTree&quot;</span>
  <span style="color: #000066;">eventNames</span>=<span style="color: #ff0000;">&quot;select:treeSelected;&quot;</span><span style="font-weight: bold; color: black;">&gt;</span></span><span style="color: #009900;"><span style="font-weight: bold; color: black;">&lt;/dojo:TreeSelector<span style="font-weight: bold; color: black;">&gt;</span></span></span>
&nbsp;
<span style="color: #009900;"><span style="font-weight: bold; color: black;">&lt;div</span> <span style="color: #000066;">dojoType</span>=<span style="color: #ff0000;">&quot;Tree&quot;</span> 
  <span style="color: #000066;">id</span>=<span style="color: #ff0000;">&quot;contentTree&quot;</span> <span style="color: #000066;">selector</span>=<span style="color: #ff0000;">&quot;treeSelector_contentTree&quot;</span>
  <span style="color: #000066;">controller</span>=<span style="color: #ff0000;">&quot;treeController&quot;</span> <span style="color: #000066;">toggle</span>=<span style="color: #ff0000;">&quot;fade&quot;</span><span style="font-weight: bold; color: black;">&gt;</span></span>
&nbsp;
  <span style="color: #009900;"><span style="font-weight: bold; color: black;">&lt;div</span> <span style="color: #000066;">dojoType</span>=<span style="color: #ff0000;">&quot;TreeNode&quot;</span> <span style="color: #000066;">title</span>=<span style="color: #ff0000;">&quot;&lt;s:property value='#request.rootNode.name'/&gt;</span>&quot;
    id=&quot;<span style="color: #009900;">&lt;s:property value='#request.rootNode.id'/&gt;</span>&quot; isFolder=&quot;true&quot;&gt;<span style="color: #009900;">&lt;/div&gt;</span>
&nbsp;
<span style="color: #009900;">&lt;/div&gt;</span>
&nbsp;
<span style="color: #009900;">&lt;/body&gt;</span>
<span style="color: #009900;">&lt;/html&gt;</span></span></pre></div></div>

<h3>struts.xml</h3>
<p>My struts.xml is pretty simple. There is one mapping to an action class which will expose methods for painting the tree and a default result for loading the jsp.</p>

<div class="wp_syntax"><div class="code"><pre class="xml"><span style="color: #009900;"><span style="font-weight: bold; color: black;">&lt;struts<span style="font-weight: bold; color: black;">&gt;</span></span></span>
   <span style="color: #009900;"><span style="font-weight: bold; color: black;">&lt;constant</span> <span style="color: #000066;">name</span>=<span style="color: #ff0000;">&quot;struts.enable.DynamicMethodInvocation&quot;</span> <span style="color: #000066;">value</span>=<span style="color: #ff0000;">&quot;false&quot;</span> <span style="font-weight: bold; color: black;">/&gt;</span></span>
   <span style="color: #009900;"><span style="font-weight: bold; color: black;">&lt;constant</span> <span style="color: #000066;">name</span>=<span style="color: #ff0000;">&quot;struts.devMode&quot;</span> <span style="color: #000066;">value</span>=<span style="color: #ff0000;">&quot;false&quot;</span> <span style="font-weight: bold; color: black;">/&gt;</span></span>
   <span style="color: #009900;"><span style="font-weight: bold; color: black;">&lt;package</span> <span style="color: #000066;">name</span>=<span style="color: #ff0000;">&quot;default&quot;</span> <span style="color: #000066;">extends</span>=<span style="color: #ff0000;">&quot;struts-default&quot;</span><span style="font-weight: bold; color: black;">&gt;</span></span>
	<span style="color: #009900;"><span style="font-weight: bold; color: black;">&lt;action</span> <span style="color: #000066;">name</span>=<span style="color: #ff0000;">&quot;tree_*&quot;</span> <span style="color: #000066;">method</span>=<span style="color: #ff0000;">&quot;{1}&quot;</span> 
            <span style="color: #000066;">class</span>=<span style="color: #ff0000;">&quot;com.codepencil.sandbox.tree.web.action.DynamicTreeAction&quot;</span><span style="font-weight: bold; color: black;">&gt;</span></span>
    	    <span style="color: #009900;"><span style="font-weight: bold; color: black;">&lt;result<span style="font-weight: bold; color: black;">&gt;</span></span></span>/tree/dynamicTree.jsp<span style="color: #009900;"><span style="font-weight: bold; color: black;">&lt;/result<span style="font-weight: bold; color: black;">&gt;</span></span></span>
        <span style="color: #009900;"><span style="font-weight: bold; color: black;">&lt;/action<span style="font-weight: bold; color: black;">&gt;</span></span></span>
   <span style="color: #009900;"><span style="font-weight: bold; color: black;">&lt;/package<span style="font-weight: bold; color: black;">&gt;</span></span></span>
<span style="color: #009900;"><span style="font-weight: bold; color: black;">&lt;/struts<span style="font-weight: bold; color: black;">&gt;</span></span></span></pre></div></div>

<h3>The Action Class</h3>
<p>In the action class I need to implement a method that will be called when child nodes of a tree are requested. When the request is made dojo passes a parameter name <em>data</em> which contains the JSON objects of the tree and the tree node that was clicked. The parameter looks something like this.</p>

<div class="wp_syntax"><div class="code"><pre class="javascript"><span style="color: #66cc66;">&#123;</span><span style="color: #3366CC;">&quot;node&quot;</span>:<span style="color: #66cc66;">&#123;</span><span style="color: #3366CC;">&quot;widgetId&quot;</span>:<span style="color: #3366CC;">&quot;1&quot;</span> isFolder=\<span style="color: #3366CC;">&quot;true&quot;</span>,<span style="color: #3366CC;">&quot;objectId&quot;</span>:<span style="color: #3366CC;">&quot;&quot;</span>,<span style="color: #3366CC;">&quot;index&quot;</span>:<span style="color: #CC0000;">1</span>,<span style="color: #3366CC;">&quot;isFolder&quot;</span>:<span style="color: #003366; font-weight: bold;">true</span><span style="color: #66cc66;">&#125;</span>, <span style="color: #3366CC;">&quot;tree&quot;</span>:<span style="color: #66cc66;">&#123;</span><span style="color: #3366CC;">&quot;widgetId&quot;</span>:<span style="color: #3366CC;">&quot;contentTree&quot;</span>,<span style="color: #3366CC;">&quot;objectId&quot;</span>:<span style="color: #3366CC;">&quot;&quot;</span><span style="color: #66cc66;">&#125;</span><span style="color: #66cc66;">&#125;</span></pre></div></div>

<p>The treeLoadingController expects the server response to be a JSON array of <em>node</em> objects. For dealing with JSON I am using the set of Java classes available at <a href="http://www.json.org/java/">json.org</a> Since my needs are very basic I can make do with these simple classes. You can use any JSON library of your choice.</p>
<p>After this I write an action class and create a function named gettreenodes which does this job for me.</p>
<p>This is my action code.</p>

<div class="wp_syntax"><div class="code"><pre class="java"><span style="color: #000000; font-weight: bold;">package</span> com.<span style="color: #006600;">codepencil</span>.<span style="color: #006600;">sandbox</span>.<span style="color: #006600;">tree</span>.<span style="color: #006600;">web</span>.<span style="color: #006600;">action</span>;
&nbsp;
<span style="color: #a1a100;">import java.io.IOException;</span>
<span style="color: #a1a100;">import java.io.PrintWriter;</span>
<span style="color: #a1a100;">import java.util.List;</span>
<span style="color: #a1a100;">import javax.servlet.http.HttpServletRequest;</span>
<span style="color: #a1a100;">import javax.servlet.http.HttpServletResponse;</span>
<span style="color: #a1a100;">import org.apache.struts2.interceptor.ServletRequestAware;</span>
<span style="color: #a1a100;">import org.apache.struts2.interceptor.ServletResponseAware;</span>
<span style="color: #a1a100;">import org.apache.struts2.showcase.ajax.tree.Category;</span>
<span style="color: #a1a100;">import org.json.JSONException;</span>
<span style="color: #a1a100;">import org.json.JSONObject;</span>
<span style="color: #a1a100;">import org.json.JSONStringer;</span>
<span style="color: #a1a100;">import com.opensymphony.xwork2.ActionSupport;</span>
&nbsp;
<span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000000; font-weight: bold;">class</span> DynamicTreeAction <span style="color: #000000; font-weight: bold;">extends</span> ActionSupport <span style="color: #000000; font-weight: bold;">implements</span> ServletResponseAware,ServletRequestAware <span style="color: #66cc66;">&#123;</span>
&nbsp;
    <span style="color: #000000; font-weight: bold;">private</span> <span style="color: #000000; font-weight: bold;">static</span> <span style="color: #000000; font-weight: bold;">final</span> <span style="color: #993333;">long</span> serialVersionUID = -9131739831820245692L;
    <span style="color: #000000; font-weight: bold;">private</span> <span style="color: #aaaadd; font-weight: bold;">String</span> data;
    <span style="color: #000000; font-weight: bold;">private</span> HttpServletResponse response;
    <span style="color: #000000; font-weight: bold;">private</span> HttpServletRequest request;
&nbsp;
    <span style="color: #000000; font-weight: bold;">public</span> <span style="color: #aaaadd; font-weight: bold;">String</span> getData<span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span> <span style="color: #66cc66;">&#123;</span>
        <span style="color: #000000; font-weight: bold;">return</span> data;
    <span style="color: #66cc66;">&#125;</span>
&nbsp;
    <span style="color: #000000; font-weight: bold;">public</span> <span style="color: #993333;">void</span> setData<span style="color: #66cc66;">&#40;</span><span style="color: #aaaadd; font-weight: bold;">String</span> data<span style="color: #66cc66;">&#41;</span> <span style="color: #66cc66;">&#123;</span>
        <span style="color: #000000; font-weight: bold;">this</span>.<span style="color: #006600;">data</span> = data;
    <span style="color: #66cc66;">&#125;</span>
&nbsp;
    <span style="color: #000000; font-weight: bold;">public</span> <span style="color: #993333;">void</span> setServletResponse<span style="color: #66cc66;">&#40;</span>HttpServletResponse response<span style="color: #66cc66;">&#41;</span> <span style="color: #66cc66;">&#123;</span>
        <span style="color: #000000; font-weight: bold;">this</span>.<span style="color: #006600;">response</span> = response;
    <span style="color: #66cc66;">&#125;</span>
&nbsp;
    <span style="color: #000000; font-weight: bold;">public</span> <span style="color: #993333;">void</span> setServletRequest<span style="color: #66cc66;">&#40;</span>HttpServletRequest request<span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#123;</span>
        <span style="color: #000000; font-weight: bold;">this</span>.<span style="color: #006600;">request</span> = request;
    <span style="color: #66cc66;">&#125;</span>
&nbsp;
    <span style="color: #000000; font-weight: bold;">public</span> <span style="color: #aaaadd; font-weight: bold;">String</span> gettree<span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#123;</span>
        Category rootNode = Category.<span style="color: #006600;">getById</span><span style="color: #66cc66;">&#40;</span><span style="color: #cc66cc;">1</span><span style="color: #66cc66;">&#41;</span>;
        request.<span style="color: #006600;">setAttribute</span><span style="color: #66cc66;">&#40;</span><span style="color: #ff0000;">&quot;rootNode&quot;</span>, rootNode<span style="color: #66cc66;">&#41;</span>;
        <span style="color: #000000; font-weight: bold;">return</span> SUCCESS;
    <span style="color: #66cc66;">&#125;</span>
&nbsp;
    <span style="color: #000000; font-weight: bold;">public</span> <span style="color: #aaaadd; font-weight: bold;">String</span> gettreenodes<span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#123;</span>
        JSONObject jsonData,node;
        <span style="color: #aaaadd; font-weight: bold;">PrintWriter</span> writer;
        <span style="color: #000000; font-weight: bold;">try</span> <span style="color: #66cc66;">&#123;</span>
            jsonData = <span style="color: #000000; font-weight: bold;">new</span> JSONObject<span style="color: #66cc66;">&#40;</span>data<span style="color: #66cc66;">&#41;</span>;
            node = jsonData.<span style="color: #006600;">getJSONObject</span><span style="color: #66cc66;">&#40;</span><span style="color: #ff0000;">&quot;node&quot;</span><span style="color: #66cc66;">&#41;</span>;
            <span style="color: #aaaadd; font-weight: bold;">String</span> nodeId = node.<span style="color: #006600;">get</span><span style="color: #66cc66;">&#40;</span><span style="color: #ff0000;">&quot;widgetId&quot;</span><span style="color: #66cc66;">&#41;</span>.<span style="color: #006600;">toString</span><span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span>;
            Category category = Category.<span style="color: #006600;">getById</span><span style="color: #66cc66;">&#40;</span><span style="color: #aaaadd; font-weight: bold;">Long</span>.<span style="color: #006600;">parseLong</span><span style="color: #66cc66;">&#40;</span>nodeId<span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span>;
            JSONStringer stringer = <span style="color: #000000; font-weight: bold;">new</span> JSONStringer<span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span>;
            stringer.<span style="color: #006600;">array</span><span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span>;
            List&lt;Category&gt; children = category.<span style="color: #006600;">getChildren</span><span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span>;  
            <span style="color: #b1b100;">for</span> <span style="color: #66cc66;">&#40;</span><span style="color: #993333;">int</span> i=<span style="color: #cc66cc;">0</span>;i&lt;children.<span style="color: #006600;">size</span><span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span>;i++<span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#123;</span>
                Category childCategory = children.<span style="color: #006600;">get</span><span style="color: #66cc66;">&#40;</span>i<span style="color: #66cc66;">&#41;</span>;
                stringer.<span style="color: #006600;">object</span><span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span>;
                stringer.<span style="color: #006600;">key</span><span style="color: #66cc66;">&#40;</span><span style="color: #ff0000;">&quot;id&quot;</span><span style="color: #66cc66;">&#41;</span>;
                stringer.<span style="color: #006600;">value</span><span style="color: #66cc66;">&#40;</span>childCategory.<span style="color: #006600;">getId</span><span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span>;
                stringer.<span style="color: #006600;">key</span><span style="color: #66cc66;">&#40;</span><span style="color: #ff0000;">&quot;title&quot;</span><span style="color: #66cc66;">&#41;</span>;
                stringer.<span style="color: #006600;">value</span><span style="color: #66cc66;">&#40;</span>childCategory.<span style="color: #006600;">getName</span><span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span>;
                stringer.<span style="color: #006600;">key</span><span style="color: #66cc66;">&#40;</span><span style="color: #ff0000;">&quot;isFolder&quot;</span><span style="color: #66cc66;">&#41;</span>;
                stringer.<span style="color: #006600;">value</span><span style="color: #66cc66;">&#40;</span>childCategory.<span style="color: #006600;">getChildren</span><span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span>.<span style="color: #006600;">size</span><span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span>&gt;<span style="color: #cc66cc;">0</span> ? <span style="color: #000000; font-weight: bold;">true</span> : <span style="color: #000000; font-weight: bold;">false</span><span style="color: #66cc66;">&#41;</span>;
                stringer.<span style="color: #006600;">endObject</span><span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span>;
            <span style="color: #66cc66;">&#125;</span>
            stringer.<span style="color: #006600;">endArray</span><span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span>;
            writer = response.<span style="color: #006600;">getWriter</span><span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span>;
            writer.<span style="color: #006600;">write</span><span style="color: #66cc66;">&#40;</span>stringer.<span style="color: #006600;">toString</span><span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span>;
        <span style="color: #66cc66;">&#125;</span> <span style="color: #000000; font-weight: bold;">catch</span> <span style="color: #66cc66;">&#40;</span>JSONException e<span style="color: #66cc66;">&#41;</span> <span style="color: #66cc66;">&#123;</span>
            e.<span style="color: #006600;">printStackTrace</span><span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span>;
        <span style="color: #66cc66;">&#125;</span> <span style="color: #000000; font-weight: bold;">catch</span> <span style="color: #66cc66;">&#40;</span><span style="color: #aaaadd; font-weight: bold;">IOException</span> e<span style="color: #66cc66;">&#41;</span> <span style="color: #66cc66;">&#123;</span>
            e.<span style="color: #006600;">printStackTrace</span><span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span>;
        <span style="color: #66cc66;">&#125;</span>
        <span style="color: #000000; font-weight: bold;">return</span> <span style="color: #000000; font-weight: bold;">null</span>;
    <span style="color: #66cc66;">&#125;</span>
<span style="color: #66cc66;">&#125;</span></pre></div></div>

<p>For creating the tree I am using the Category class from the struts showcase application as I was feeling too lazy to write a brand new class for this purpose. In my actual application I have some complex hibernate mappings and I load the tree node objects from the database.</p>
<p>Another important thing that caused me a lot of frustration is that you should always return <strong>null</strong> from an action method that handles ajax calls otherwise you wont get the desired result.</p>
<h3>The Sample Application</h3>
<p>The code of the full application can be downloaded from the following link. You can simply deploy this as it is in a container. (I have tested it with Tomcat5.5 and jdk6)</p>
<p><a href="/code/struts2-dynamic-tree-application.zip">Download the Dynamic Tree Sample Application</a></p>
<p>You can use the tree loading controller for saving and restoring the state of the tree in a similar way as in the <a href="?p=4">previous example</a>.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.codepencil.com/index.php/struts2-dojo-dynamic-tree/feed/</wfw:commentRss>
		<slash:comments>39</slash:comments>
		</item>
	</channel>
</rss>
