Tech I Enjoy Logo

Custom Search




  Home >> Struts


There could be many ways of creating Tree structure while working
with DOJO, Struts2 Plugin for DOJO.

In this example I shall try to cover a very simple way of putting
various pieces of code together to come up with a Tree Layout for
displaying set of Books as a case study.

In this example this particular Tree structure will be formed out
of a dynamically populated object at server side.

This object will have a parent-child association with multiple instances
of the same class as child to the root node.

This means, if Book is a case study class in this example, then it
can have other Book instances as child stored inside the parent Book
object with a data type as List.

Book.java
package example;
import java.util.List;

public class Book
{
  private String bookId;
  private String bookName;
  private List<Book> booksList;

  public void setBookId(String bookId) {
	  this.bookId = bookId;
  }
  public String getBookId() {
	  return this.bookId;
  }
  public void setBookName(String bookName) {
	  this.bookName = bookName;
  }
  public String getBookName() {
	  return this.bookName;
  }
  public void setBooksList(List booksList) {
	  this.booksList = booksList;
  }
  public List<Book> getBooksList() {
	  return this.booksList;
  }

}
Now, the actual Tree widget values will be mapped to this Book instance that is created within a method of this example Action class, as follows: BooksTreeAction.java
package example;
import java.util.List;
import java.util.ArrayList;

import com.opensymphony.xwork2.ActionSupport;

public class BooksTreeAction extends ActionSupport
{
    public Book getBooksTree() {

      Book bk = new Book();
      bk.setBookId("BK001");
      bk.setBookName("Java Books");

      Book bk1 = new Book();
      bk1.setBookId("C001");
      bk1.setBookName("Books");
      List list = new ArrayList();
      list.add(bk);
      bk1.setBooksList(list);

      return bk1;
   }
}
In order to make this example work, it is needed to complete action mapping in struts.xml file and writing the appropriate JSP file as mentioned in ths action result. 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-example1" namespace="/example1"
                 extends="struts-default">
        <action name="tree-example1" class="example.BooksTreeAction">
                <result>/sample.jsp</result>
        </action>
    </package>

</struts>
and the sample.jsp file
<%@ taglib uri="/struts-dojo-tags" prefix="s2d"%>
<html>
<head><title></title>
<s2d:head cache="true"/>
</head>
<body>
<div>
  <s2d:tree id="treeOfBooks" rootNode="%{booksTree}" 
            nodeIdProperty="bookId" nodeTitleProperty="bookName" 
            childCollectionProperty="booksList"/>

</div>
</body>
</html>
This rootNode (value of this attribute is booksTree) should be inline with the getter method name in the action mapping which is getBooksTree in this case. Other attributes of the tree tag are pretty straight forward to co-relate. In order to test this example, the URL is as follows: http://localhost:8080/struts2-and-dojo/example1/tree-example1 where localhost being the local machine and 8080 being the Tomcat web server listening port for this example's runtime environment. example1 being the namespace and tree-example1 being the action name. Hope this helps. If anything missed out , please let me know at techienjoy at yahoo . com
Apache Struts 2 upload Example :
Uploading Example Steps of using Struts 2
and Example code explained.
Apache Struts Date Validation with Example :
Example of Date Validation using Struts and 
code explained.
Apache Struts 2 and XSLT With Example :
XSLT Example using Struts 2 and Example 
code explained.
Apache Struts 2 Validation Example :
Validation Example Steps of using Struts 2
and Example code explained.
Apache Struts 2 Tags Example :
Example Steps of using Struts 2 Tags
and code explained.
Struts 2 Plugin Example :
Example using Struts 2 Plugin
Apache Struts with DOJO Example Part-4 :
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 2 Example Steps :
Example Steps of using Struts 2 and code explained.
Apache Struts 2 Radio Tag Example :
Example Steps of using Struts 2 Radio Tags
and code explained.
Apache Struts 2 Validation With Expression :
Validation with Expression using Struts 2
and Example code explained.
Apache Struts Validation with Example :
Example of Validation using Struts and 
code explained.
Apache Struts with DOJO Example Part-2 :
Example of DOJO Toolkit with Struts and 
code explained.
Apache Struts 2 Validation With Example :
Validation 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.
Struts 2 with JSF Example :
Example using JSF with Struts 2 and 
code explained.
Apache Struts with DOJO Example Part-1 :
Example of DOJO Toolkit with Struts and 
code explained.
Apache Struts 2 Custom Validator :
Example Steps of using Struts 2 with Custom Validator
and code explained.
Struts 2 Result Chain Example :
Example using Result Chain with Struts 2 and 
code explained.
Apache Struts 2 Result PlainText Example :
Example Steps of using Struts 2 PlainText Result
and code explained.
Struts Validation Example :
Example using Validation with Struts 2 and 
code explained.
List of Struts Example :
Examples List using Struts 2 and 
code explained.
Apache Struts with DOJO Example Part-3 :
Example of DOJO Toolkit with Struts and 
code explained.
Apache Struts 2 Tags Example :
Example of Struts 2 Tags and 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