Advertisement :
   Log In    OR    Register  
  Topics :  
RMI Example

Home >>> Struts Struts 2 Example Tutorial >>> Struts2 Plugin DOJO >>> TreeNode Mapped POJO Value
Struts Tutorials:
Struts2 Tag CheckBoxList
, Checkbox, Iterator, IF
Struts2 Tag Library Example Struts2 Tiles Example Struts2 Tiles I18N Example Struts2 Questions Struts Tiles I18N Example Struts Eclipse MVC Struts2 Tags Struts2 Example and Tutorial Struts MVC Struts2 Validation
Hibernate Tutorials: Hibernate Case Study Class Hierarchy Persist Example Using Hibernate Interceptor Hibernate Questions with Answer Hibernate Many-to-Many Mapping Example Hibernate one-to-many Mapping Example Hibernate and ORM tools Spring Hibernate Example Hibernate SessionFactory Example Hibernate Mapping Class Hierarchy Hibernate Questions Hibernate SessionFactory Questions Spring Hibernate Example: Spring Hibernate Case Study

Written By : ISHTEK
Title :
Struts2
Description : Tags such as IF Iterator Tags
More...


Written By : guddu
Title :
Struts Eclipse MVC
Description : Step by step demonstration
More...


Written By : Girish
Title :
Struts Tiles I18N Example
Description : Code with Sample Action
More...


Written By : ISHTEK
Title :
Struts2 questions
Description : open for discussion
More...


Written By : ISHTEK
Title :
Struts2 Tiles Example
Description : with Code and article
More...


Written By : ISHTEK
Title :
Struts2 Tiles I18N Example
Description : with code explained article
More...


Written By : Amit
Title :
Struts2 Tag Library Example
Description : Tutorial
More...

Tags/Keywords : Struts, Struts2 Tutorial, Struts 2 Example, Struts2
Author : ISHTEK
Date (Year/Month/Date): 2010-05-29 Example using Struts2 Plugin for DOJO - Tree Structure from a POJO Object Graph

Please be informed that NONE of the design/code/matter from this page is claiming to be some
sort of best practice and we DO NOT expect any of our visitor/reader of this page to assume
this as some sort of best practice for any context and should not be using this as it is
without appropriate evaluation.
This page intends only to provide bits and pieces of known ways  for doing some sort of example
and may not be fit for any other purpose.

In spite of all precautions taken to provide accurate and avoid any typo in these pages,
there might be some issues like grammatical mistakes and typo being observed in these pages,
We extend our sincerest apologies for the same.


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.


	
Please write your Comment on this Matter
(This will be visible if found suitable):
Name: *
Email (will not be displayed): *
Matter: *
14,4
Enter bigger number from above :*
Home >>> Struts Struts 2 Example Tutorial >>> Struts2 Plugin DOJO >>> TreeNode Mapped POJO Value
Visitor/User referred related external URL:
(Visible upon review and approved by this site Administrator)
Referred By Name *:
Resource URL *: (e.g, URL should be starting with http://www.-----.---)
 
Resource Short Description *:
11,21
Enter bigger number from above : *

Please log in to add or reply to any matter<- requires login
Log in or Register
Copyright © 2008-2010, Interview-Questions-Tips-Forum, All Rights Reserved.
CONTACT    PRIVACY POLICY    DISCLAIMER
 

Oracle and Java are registered trademarks of Oracle and/or its affiliates.
Other names may be trademarks of their respective owners

This web site's Terms of Use and Disclaimer :

This web site provides some of the information about various technologies, example code, tips, tutorials etc. Like any printed materials,
content of these pages may become out of date over a period of time. Therefore all visitor/users of this web site are requested/advised
to refer to the originating parties/sources for the latest changes and happenings for detailed information. This information is not
intended to be a substitute for the original reference provided by the originating parties/sources. These examples with source code or
without source code, have not been thoroughly tested under all conditions. Interview-questions-tips-forum.net therefore, cannot guarantee
or imply reliability of these example source code or programs.

By accessing and using this website in any ways, including, without limitation, browsing the website pages, using any information, using
any content and/or downloading any materials, you agree to and are bound by the terms of use described in this page and Usage Terms and Conditions.
If you do not agree to all of the terms and conditions contained in the terms of use described in this page and
Usage Terms and Conditions, do not use this website in any manner. If you are using the website on behalf of your
employer, you represent that you are authorized to accept these Terms of Use on your employer's behalf.

All Trademarks are property of their respective owner. Appropriate measure is being taken for providing accurate and up-to-date
information but like any printed materials, these blog(s)/contents may eventually be outdated one day, so if you are using any of these
information, please refer original content/documentation from respective sources. And under no circumstances shall the Author of these
contents and/or this web site be liable for any loss, damage, expense incurred or suffered which is claimed to have occurred because of
usage of the contents of this web site. If you have any questions/queries/feedback/suggestions then please write to this web site owner
at contact.