Tech I Enjoy Logo

Custom Search




  Home >> Struts


Rendering DOJO Tree Widget using Struts2 Plugin for DOJO

I hereby will try to quickly discuss an example with Tree widget
using Struts2 Plugin for DOJO, along with a demo action and
dynamically populating Tree Node on click of the + sign.

This example uses AJAX way of rendering/populating dynamic 
runtime values from the view JSP, thus making this example
more useful in comparison to my earlier example, where
I just showed a possible way to render a Tree widget by
some statically coded TreeNodes.

Various pieces of this example includes required JAR files
from the Struts 2.1.8 distribution (I have used this version
of Struts 2 in my local example setup environment), simple
web application setup with a struts.xml file, web.xml file
and two JSP files and a Action class .

My example folder and file structure is as follows:

example
  |
  |_____ sample.jsp     (Main JSP file)
  |_____ sampletree.jsp (Suppliment file for providing JSON string
  |                        based on nodeId from request parameter)
  |
  |_____ WEB-INF
            |
	    |_____lib
	           |____ commons-fileupload-1.2.1.jar
		   |____ commons-io-1.3.2.jar
		   |____ commons-logging-1.1.jar
		   |____ freemarker-2.3.13.jar
		   |____ ognl-2.6.11.jar
		   |____ struts2-core-2.1.8.1.jar
		   |____ struts2-dojo-plugin-2.1.8.1.jar
		   |____ xwork-core-2.1.6.jar
            |
	    |_____ web.xml
	    |
	    |_____ classes
	           |
		   |_____ struts.xml
		   |_____ example
		            |
			    |_____ TreeRenderAction.java (Action class file)
After setting up all these files, I tested this example by a URL on browser as follows: http://<machine_ip>:port/example/sample.jsp Let us explore all the files created for this example : sample.jsp

<%@ taglib uri="/struts-dojo-tags" prefix="s2d"%>
<html>
<head><title></title>
<s2d:head cache="true"/>
</head>
<body>
<div>
<s2d:tree id="tree" href="example/tree-example"/>
</div>
</body>
</html>
sampletree.jsp

<%
String nodeId = (String)request.getParameter("nodeId");
System.out.println("node id:"+nodeId);
%>
<% if(nodeId != null && nodeId.equals("books")) { %>
[ { label: "Java Books", hasChildren: true, id: "JavaBooks" } ]
<% } else if (nodeId != null && nodeId.equals("JavaBooks")) { %>
[ { label: "Threading Books", hasChildren: false, id: "ThreadBooks" } ,
  { label: "Networking Books", hasChildren: false, id: "NetworkingBooks" } ,
  { label: "GUI Books", hasChildren: false, id: "GUIBooks" } ]
<% } else {%>
[ { label: "Books", hasChildren: true, id: "books" } ]
<% } %>
As this sampletree.jsp file is receiving the request with default parameter as nodeId with a value as the id of the node that is clicked on screen/browser Tree widget. So depending on the id, appropriate sub/child tree node per se are supplied as response in form of JSON string array. web.xml
<?xml version="1.0" encoding="UTF-8"?>

<!DOCTYPE web-app
    PUBLIC "-//Sun Microsystems, Inc.//DTD Web Application 2.3//EN"
    "http://java.sun.com/dtd/web-app_2_3.dtd">

<web-app>
    <display-name>Struts2 and DOJO example</display-name>
  <filter>
  <filter-name>sample-filter</filter-name>
  <filter-class> 
    org.apache.struts2.dispatcher.ng.filter.StrutsPrepareAndExecuteFilter
  </filter-class>
  </filter>
  <filter-mapping>
    <filter-name>sample-filter</filter-name>
    <url-pattern>/*</url-pattern>
  </filter-mapping>
</web-app>
struts.xml
<?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>
 <package name="dojo-tree-example" namespace="/example"
          extends="struts-default">
  <action name="tree-example" class="example.TreeRenderAction" 
          method="preview">
   <result name="preview">/sampletree.jsp</result>
  </action>
 </package>
</struts>
The href attribute of the tree widget tag from Struts2 Plugin has the namespace and action as depicted in bold letters in the above sample.jsp file, as mentioned here as well "example/tree-example" So on click of the node, this action is called and it goes through the preview method and then to the sampletree.jsp file as mentioned in the result value in the struts.xml configuration file. TreeRenderAction.java
package example;

public class TreeRenderAction {
  public String preview() {
	  return "preview";
  }
}
Hope this helps. If anything missed out , please let me know at techienjoy at yahoo . com
Apache Struts 2 Custom Validator :
Example Steps of using Struts 2 with Custom Validator
and code explained.
Apache Struts with DOJO Example Part-4 :
Example of DOJO Toolkit with Struts and 
code explained.
Struts 2 with JSF Example :
Example using JSF with Struts 2 and 
code explained.
Apache Struts 2 Validation With Expression :
Validation with Expression using Struts 2
and Example code explained.
Struts Validation Example :
Example using Validation with Struts 2 and 
code explained.
Apache Struts 2 Tags Example :
Example Steps of using Struts 2 Tags
and code explained.
Apache Struts with DOJO Example Part-2 :
Example of DOJO Toolkit with Struts and 
code explained.
Struts 2 Tiles and I18N Example :
Example using Tiles and I18N with Struts 2 and 
code explained.
Apache Struts 2 Tiles and I18N Example :
Example Steps of using Struts 2 With Tiles
and I18N code explained.
Apache Struts with DOJO Example Part-3 :
Example of DOJO Toolkit with Struts and 
code explained.
Apache Struts 2 Example Steps :
Example Steps of using Struts 2 and code explained.
Apache Struts Date Validation with Example :
Example of Date Validation using Struts and 
code explained.
Apache Struts 2 Tags Example :
Example of Struts 2 Tags and code explained.
Apache Struts with DOJO Example Part-1 :
Example of DOJO Toolkit with Struts and 
code explained.
Struts 2 Plugin Example :
Example using Struts 2 Plugin
Struts 2 Result Chain Example :
Example using Result Chain with Struts 2 and 
code explained.
Apache Struts 2 Validation Example :
Validation Example Steps of using Struts 2
and Example code explained.
Apache Struts Validation with Example :
Example of Validation using Struts and 
code explained.
Apache Struts 2 Radio Tag Example :
Example Steps of using Struts 2 Radio Tags
and code explained.
Apache Struts 2 Result PlainText Example :
Example Steps of using Struts 2 PlainText Result
and code explained.
Apache Struts 2 and XSLT With Example :
XSLT Example using Struts 2 and Example 
code explained.
Apache Struts 2 PDF Result :
Example Steps of using Struts 2 with PDF Result
and code explained.
List of Struts Example :
Examples List using Struts 2 and 
code explained.
Apache Struts 2 upload Example :
Uploading Example Steps of using Struts 2
and Example code explained.
Apache Struts 2 Validation With Example :
Validation Example using Struts 2
and Example code explained.


References :
Tags: Struts 1 Struts2 plugin
Tags: struts jsf integrate
Tags: struts result chain
Tags: struts tiles i18n
Tags: Struts validation struggle
Tags: Struts
Tags: struts1 date validation
Tags: struts1 struts2 validation
Tags: struts2 dojo 1
Tags: struts2 dojo 2
Tags: struts2 dojo 3
Tags: struts2 dojo 4
Tags: Struts2 example steps Tag usage
Tags: Struts2 example steps
Tags: struts2 own validator
Tags: struts2 pdf result
Tags: struts2 radio tag example
Tags: struts2 result plaintext
Tags: struts2 tags example
Tags: struts2 tiles i18n
Tags: struts2 upload example
Tags: struts2 validation 1
Tags: struts2 validation expression
Tags: struts2 validation
Tags: struts2 xslt article



DISCLAIMER :
The content provided in this page is not warranted and/or guaranteed by techienjoy.com. 
techienjoy.com is not liable for any negative consequences that may result/arise from 
implementing directly/indirectly any information covered in these pages/articles/tutorials.

All contents of this site is/are written and provided on an "AS IS" basis,
without WARRANTIES or conditions of any kind, either express or implied, including, without
limitation, merchantability, or fitness for a particular purpose. You are solely responsible
for determining the appropriateness of using or refering this and assume any risks associated
with this.

In spite of all precautions taken to avoid any typo in these pages, there might be some 
issues like grammatical mistakes and typos being observed in these pages, techienjoy.com
extends sincerest apologies to all our visitors for the same.



Android Examples || Android Examples

© Copyright 2010-2012, TECHIENJOY, All Rights Reserved.      Privacy Policy     Disclaimer & Terms & Conditions