Home >> Struts
Using DOJO and Struts2 example :
In this example I shall be showing one of the way to create
a Tree of treenodes using Struts2 Plugin for Dojo.
For this example I am using Struts2 version 2.1.8.1
along with JDK 6 and Tomcat web server 6.0.18 to be
very precise. As I have testing this example only with
the above software versions, I am not sure how this example
will behave in any other versions of Struts 2 Framework.
Now coming back to this example, let me touch upon a very
brief explanation to the objective I am trying to emphasis.
This example is going to create or show a very simple tree
structure like as follows, with some interleaved tree nodes.
|
|  |
|
This example is about statically supplied tree and tree nodes,
this means this tree structure is not controlled by any
change in application data, instead this tree is just showing
the values those are statically defined/supplied at compile time.
Later point of time, I shall definitely find some time to re-create
this example tree with some dynamically supplied values from
some data store.
For now let us try to setup the web application deployment
environment using Struts2 Framework along with DOJO specific
plugin such as for my example I have used following JAR files
under /WEB-INF/lib folder:
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
As I have used web app 2.3 as the web application descriptor setting
and the Struts 2 specific prepare and execute filter needs to be
set up in web.xml file: So my example web.xml file for your reference
as follows:
<?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 & 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>
|
As I havn't used any type server side action as such, so this example
is pretty much stripped down to only two example specific files
such as sample.jsp and the web.xml:
sample.jsp for your reference as follows:
<%@ taglib uri="/struts-dojo-tags" prefix="s2d"%>
<html>
<head><title></title>
<s2d:head cache="true"/>
</head>
<body>
<div>
<s2d:tree id="books" label="Books" title="test" >
<s2d:treenode label="Java" title="test">
<s2d:treenode id="Thread-Books" label="Multi-threading" />
<s2d:treenode id="Thread-Books" label="Core-Java" />
<s2d:treenode id="Thread-Books" label="Networking" />
</s2d:treenode>
</s2d:tree>
</div>
</body>
</html>
|
So very important points to remember here is one, the entry for
the tag library specific to dojo, two, DOJO head tag should be
present inside the HTML head tag.
Hope this is quite simple enough to try out, without really
spending much time on setting up the software environment
to start with.
If anything missed out , please let me know at
techienjoy at yahoo . com