Contact Us
  
 
 
    SearchSearch   RegisterRegister   Log inLog in 

tree view in jsp

tree view in jsp

 
Post new topic   Reply to topic     Forum Index -> Java,Struts framework, Velocity, JSF, Hibernate, Servlet, JSP, javaBeans
View previous topic :: View next topic  
Author Message
jorous



Joined: 28 Mar 2007
Posts: 3

PostPosted: Wed Mar 28, 2007 11:54 am    Post subject: tree view in jsp Reply with quote




i want to show data in tree view format, i want to do it without using tag libraries in java, jsp. dont know how it will happened
Back to top
View user's profile Send private message
magicgenie



Joined: 20 Apr 2007
Posts: 4

PostPosted: Fri Apr 20, 2007 1:29 pm    Post subject: tree view in jsp Reply with quote

hi,
I want to thanks my friend priya.
you have to do recursive in query whatever ur sql database. i m using this mysql.
i got concept from http://treemenu.net but they donot provide that source in jsp. i got that code in javabean and old version. then i see in code dot net.That was working fine. And i changed that code in jsp. it is working fine here.

first


Code:


<%@ page contentType="text/html; charset=iso-8859-1" language="java" import="java.sql.*,java.util.StringTokenizer,java.util.*,java.text.*" errorPage="" %>

<%
         
             Connection conn =null;
              Class.forName("org.gjt.mm.mysql.Driver");
         try{
           conn = DriverManager.getConnection("jdbc:mysql://localhost/yourDatabaseName","root","password");
         String tempNodeID=nullconv(request.getParameter("NodeID"));
         int tempdownline=nullIntconv(nullconv(request.getParameter("downline")));
         setConnection(conn,out,tempNodeID,tempdownline);
         }
         catch(Exception e)
         {
           e.printStackTrace();
         }
%>

<%!
public String nullconv(String str)
{
   if(str==null)
      str="";
   else if(str.equalsIgnoreCase("null"))
      str="";
   else if((str.trim()).equals(""))
      str="";
   return str;
}
public int nullIntconv(String inv)
   {
      if(inv==null)
      {
         inv="0";
      }
      else if((inv.trim()).equals("null"))
      {
         inv="0";
      }
      else if(inv.equals(""))
      {
         inv="0";
      }
      
      return Integer.parseInt(inv);
   }


       Connection con=null;   

      PreparedStatement pstmt = null;
      PreparedStatement pstmt1 = null;

      ResultSet rs = null;
      ResultSet rs1 = null;

      JspWriter out=null;
      String   NodeID =  "1";
       int downline = 0;
      
   public void setConnection(Connection con,JspWriter ot,String rq,int dwline)
   {
      this.con=con;
      try{
      this.out=ot;
      NodeID=rq;
      downline=dwline;
    
       if(NodeID.equals(""))
         {
          NodeID="1";  ///////////////////// change this according to your requirement
         }
         if(downline==0)
         {
          downline=20;   ////////////////////// this is for advance requirement should use according to your requirement
         }
      }
      catch(Exception e)
      {
         System.out.println("IO error :"+e);
      }
    
    }
   
   
   public void outputJavascriptForRoot()
   {
            
      String queryString =null;
      
      queryString ="SELECT NodeID, Name, IsFolder, ParentID, Link, level FROM NodesTable WHERE (NodeID='" + NodeID +"')";
      try{
      
      pstmt=con.prepareStatement(queryString);
      rs=pstmt.executeQuery();
      
      // It should return one and one only
      while (rs.next())
      {
        out.print("foldersTree = gFld('<i>tree</i>')" + "\n");
        out.print("web" + rs.getString("NodeID") + " = insFld(foldersTree, gFld('" + rs.getString("Name") + "[" + rs.getString("NodeID") + "]"  + "','tree.jsp?distibutorid=" + rs.getString("NodeID") + "&downline="+downline+"'))" + "\n");
        outputJavascriptForSubFolder(Integer.parseInt(rs.getString("NodeID")), rs.getString("Name"),"web" + rs.getString("NodeID"), rs.getString("Link"), downline);
      }
      
      // close the DataReader and Connection
      
      
   
      }
      catch(SQLException ex)
      {
        System.out.println("sqll eroror :"+ex);
       }
       catch(Exception e)
       {
          System.out.println("error :"+e);
       }
   }
   
   
 public void outputJavascriptForSubFolder(int folderId, String Name, String fName, String Link, int downline)
   {
      
   try{
      PreparedStatement psQueryString = null;
      ResultSet rsqueryString = null;
       String queryString1 ="SELECT NodeID, Name, IsFolder, ParentID, Link FROM NodesTable WHERE ((ParentID=" + folderId + ") AND (IsFolder=1) AND level<=" + downline + ") ORDER BY Name";
      psQueryString=con.prepareStatement(queryString1);
      rsqueryString=psQueryString.executeQuery();
      
      
      // iterate through the rows in the Nodes table
         while(rsqueryString.next())
         {
         out.print("web" + rsqueryString.getString("NodeID") + "=insFld(" + fName + ",gFld('" + rsqueryString.getString("Name") + "[" + rsqueryString.getString("NodeID") + "]','tree.jsp?NodeID="+rsqueryString.getString("NodeID")+"&downline="+downline+"'))  " + "\n" );
         outputJavascriptForSubFolder(Integer.parseInt(rsqueryString.getString("NodeID")),rsqueryString.getString("Name"),"web" + rsqueryString.getString("NodeID"),rsqueryString.getString("Link"),downline);
         }
     }
   catch(Exception e)
      {
        System.out.println(e);
      }
   }
 
%>

<html>
<head>

<title>Tree from database</title>

<style type="text/css">
   BODY {background-color: white}
   TD {font-size: 10pt;
       font-family: verdana,helvetica;
      text-decoration: none;
      white-space:nowrap;}
   A  {text-decoration: none;
       color: black}
</style>

<!-- As in a client-side built tree, all the tree infrastructure is put in place
     within the HEAD block, but the actual tree rendering is trigered within the
     BODY -->

<!-- Code for browser detection -->
<script language="javascript" src="ua.js"></script>
<script language="javascript" src="ftiens4.js"></script>
<!-- Execution of the code that actually builds the specific tree.
     The variable foldersTree creates its structure with calls to
    gFld, insFld, and insDoc -->
<script language="javascript">
USETEXTLINKS = 1
STARTALLOPEN = 1
PRESERVESTATE = 1
ICONPATH = ''
HIGHLIGHT = 1
<%
outputJavascriptForRoot();
%>


// Load a page as if a node on the tree was clicked (synchronize frames)
// (Highlights selection if highlight is available.)
function loadSynchPage(xID)
{
   var folderObj;
   docObj = parent.treeframe.findObj(xID);
   docObj.forceOpeningOfAncestorFolders();
   parent.treeframe.clickOnLink(xID,docObj.link,'basefrm');

    //Scroll the tree window to show the selected node
    //Other code in these functions needs to be changed to work with
    //frameless pages, but this code should, I think, simply be removed
    if (typeof parent.treeframe.document.body != "undefined") //scroll doesn work with NS4, for example
        parent.treeframe.document.body.scrollTop=docObj.navObj.offsetTop
}
</script>
</head>

<body topmargin=16 marginheight=16>

<!-- By removing the follwoing code you are violating your user agreement.
     Corporate users or any others that want to remove the link should check
    the online FAQ for instructions on how to obtain a version without the link -->
<!-- Removing this link will make the script stop from working -->
<div style="position:absolute; top:0; left:0; "><table border=0><tr><td><font size=-2><a style="font-size:7pt;text-decoration:none;color:silver" href="http://www.treemenu.net/" target=_blank>JavaScript Tree Menu</a></font></td></tr></table></div>

<!-- Build the browser's objects and display default view of the
     tree. -->
<script language="javascript">
initializeDocument()
//Click the Parakeet link
loadSynchPage(11)
</script>
<noscript>
A tree for site navigation will open here if you enable JavaScript in your browser.
</noscript>
</body>
</html>


create database

and this table

Code:



CREATE TABLE  nodestable (
  `NodeID` int(10) unsigned NOT NULL auto_increment,
  `Name` varchar(45) NOT NULL default '',
  `IsFolder` int(10) unsigned NOT NULL default '0',
  `ParentID` int(10) unsigned NOT NULL default '0',
  `Link` varchar(45) NOT NULL default '',
  `level` int(11) default NULL,
  PRIMARY KEY  (`NodeID`)
) ENGINE=MyISAM DEFAULT CHARSET=latin1;


This is for mysql database you can use any one

insert this data record in table

Code:

INSERT INTO `nodestable` (`NodeID`,`Name`,`IsFolder`,`ParentID`,`Link`,`level`) VALUES
 (1,'A',1,0,'1',1),
 (2,'B',1,1,'1',2),
 (3,'C',1,1,'1',2),
 (4,'E',1,2,'1',3),
 (5,'F',1,2,'1',3),
 (6,'G',1,3,'1',3),
 (7,'H',1,3,'1',3),
 (8,'I',1,4,'1',4),
 (9,'J',1,4,'1',4),
 (10,'K',1,5,'1',4),
 (11,'L',1,5,'1',4),
 (12,'M',1,6,'1',4),
 (13,'N',1,6,'1',4),
 (14,'O',1,7,'1',4),
 (15,'P',1,7,'1',4),
 (16,'R',1,11,'1',6);



You can down this Source code of tree in jsp Download

then run this good luck

more reference

http://www.treemenu.net

http://www.treeview.net
Back to top
View user's profile Send private message
vivk12



Joined: 30 Apr 2007
Posts: 1

PostPosted: Mon Apr 30, 2007 4:50 pm    Post subject: tree view in jsp Reply with quote

This code is working fine in jsp. But today it is time of to switch struts. I want to do tree view in struts. Can you give me solution in struts as this tree as same in jsp
Back to top
View user's profile Send private message
jorous



Joined: 28 Mar 2007
Posts: 3

PostPosted: Thu May 10, 2007 5:57 pm    Post subject: jsp tree Reply with quote

i have listen that, we can make tree easily in tag lib in java jsp. this is in built method that do own and draw tree for us. i have studied on internet and find some site on this tree http://www.guydavis.ca/projects/oss/tags/ and apache own also have tag lib on tree view http://beehive.apache.org/docs/1.0/netui/tagsTree.html hope this will help you. and you will also help me on tree view
Back to top
View user's profile Send private message
rimo1005



Joined: 11 May 2007
Posts: 2

PostPosted: Fri May 11, 2007 4:28 pm    Post subject: tree in jsp Reply with quote

Anyone can give me idea of drawing tree in simple html or javascript. because i can not use server side or any programmering language. :( so i have left only one option. make a tree in html javascript. But i dont have any idea of this. plz help :P
Back to top
View user's profile Send private message
biba



Joined: 16 May 2007
Posts: 1

PostPosted: Wed May 16, 2007 1:14 pm    Post subject: tree in jsp Reply with quote

There many site who provide tree in html and jsp server side.
check out for html tree
http://www.mattkruse.com/javascript/mktree/
this will help u to draw tree in html . there is many tree menu available but that are not free, try out on google to search it.
Back to top
View user's profile Send private message
admin
Site Admin


Joined: 24 Aug 2006
Posts: 30

PostPosted: Sat Nov 22, 2008 2:55 pm    Post subject: Reply with quote

jQuery TreeView Menu is also option for tree view

check out hot thing of javascript jQuery

http://www.dynamicdrive.com/dynamicindex1/treeview/index.htm
Back to top
View user's profile Send private message Send e-mail
juniormember



Joined: 28 Jun 2008
Posts: 154

PostPosted: Wed Jul 01, 2009 4:46 pm    Post subject: Reply with quote

Hi Friends,

I would like to display database contents as simple treeview structure. The example is given in this website is complicated as i am not able to implement. Can any one help me out how to write simple jsp tree and show the database values? I need to view one field and its values. For example i have to show the clients name as tree view. If i click the client name i have to dispaly the project name. So that i have to render the tree which the value shoud query from the database. Thanks in advance. Have a nice day........

Regds,
Mike
Back to top
View user's profile Send private message
Display posts from previous:   
Post new topic   Reply to topic     Forum Index -> Java,Struts framework, Velocity, JSF, Hibernate, Servlet, JSP, javaBeans All times are GMT
Page 1 of 1

 
Jump to:  
  Quick Post a Reply Topic
     
  Name (required)  
     
  Email Address (will not be published) (required)  
     
  Subject of topic (required)  
     
   
     
   
     
  Advertisement  
     
 
     


  More Links  
 
JSP Introduction
JSP Setup
Simple JSP Example
JSP Variable
Array Declaration in JSP
JSP Forms and User Input
Form Validation
JSP Cookies
JSP Session Object
Loop, content collection, iterator, conditional check in JSP
JSP Application Object
JSP Include
JSP Response Object
JSP Request Object
JSP Error Handling
JSP File Handling Object
JSP Action Tag
JSP Implicit Objects
JSP Declaration
JSP Directive
JDBC Introduction
JDBC Driver
JDBC Connection
JDBC Prepared/Statement
JDBC ResultSet
JDBC Close Connection object
JDBC Insert
JDBC Display Records
JDBC Update
JDBC Delete
JDBC Sorting
JDBC Query
JDBC Exception
JDBC Add Batch
JDBC Transaction/RollBack