Tree Structure Implementation in Java.

1>
How should i implement a "Tree Structure" in Java Based application.?How would i map the entries to the database table?how many tables will i require for this implementation.?
List records<String> = new ArrayList<String>();
records.add("null");
records.add("Product");
records.add("Category");
records.add("P1");
records.add("P2");
records.add("P3");
records.add("C1");
records.add("C2");
records.add("C3");
so how should i implement a Tree Structure for the above record set.
//P1,P2,P3 belong to Parent {Product}
//C1,C2,C3 belong to Parent {Category}
Sample code provided will be helpful

How should i implement a "Tree Structure" in Java Based application.?The quotes suggest you don't know what a tree structure is, regardless of the development language. Fix that first (your understanding of what a tree structure is). [url http://en.wikipedia.org/wiki/Tree_structure]Here is probably a good start.
How would i map the entries to the database table?how many tables will i require for this implementation.?It depends on what your tree structure represents, in particular it depends on whether the leaves and intermediate nodes of the trees have are homogeneous (e.g. have a common interface). There is no general rule.
I suggest you start by looking in the Java API at all the classes whose names start with 'Tree' (TreeSet and TreeMap are probably the best ones to start with) and read the documentation carefully. Then try to write some code that uses one and come back if/when you have any problems.(sorry Winston) I think this is a very bad advice.
These classes are particular implementations, respectively of a set (in the mathematical sense) and of a map (associative table), which happen to use a "tree structure" for their internal business. Their API doesn't help building a custom "tree structure" (they may be used that way, but it's certainly not the easiest nor even a particular handy way to build tree structures).
Maybe their implementation may be a good example of how to build a Tree structure, but they use a particular type of tree (+red-black tree), not a general one. This may or may not be the OP's case, I wouldn't bet on it.
OP you're welcome to come back with more specific questions and details. Good luck with Java.
Edited by: jduprez on Oct 16, 2010 2:45 PM
Edited by: jduprez on Oct 16, 2010 2:49 PM
After checking the Javadoc: indeed TreeSet only uses a TreeMap for its implementation, so the only one out of the two which does directly uses a tree structure in its implementation is TreeMap.
Edited by: jduprez on Oct 16, 2010 2:51 PM
And, to reiterate, I stand by my claim that TreeMap is not a good example of a general Tree structure: in particular it uses a tree to map keys to values, its main business is the "mapping" part, not the tree as a storage medium. Neither the keys nor the values know anything about their "children".

Similar Messages

  • How can I create a Tree  Structure in java ??

    Hi,
    I want to create a tree structure(objects hierarchy) using java language. Is there any API method for this ?
    Can any one please give me a hint or suggestion how I can do this ??
    Thanks for the help in advance.

    Do you mean graphically?
    You can use a TreeSet or TreeMap if you just want to use tree structures.
    Kaj

  • How do I implement Tree structure in table in JSP?

    Hi
    how do I implement Tree structure in table in JSP? any body suggest?
    Thanks
    siva

    If you're using JSP+JSTL, use the JSTL's c:forEach tag. If you're using JSP+JSF, use the Tomahawk's t:tree tag.

  • How to Implement Dynamic Tree structure in jsp

    Hi,
    Does any body help me to solve out my requirement??
    I want to display all my folder contents (parent & childs) in windows explorer format, the root folder path will come from database.
    Thanks in advance

    There are many ways to achieve this. The simplest would be to use some existing tag library that renders a tree structure and feed it with the required data.

  • Listing File Hierarchy in console using a Tree structure

    first off i'm a college student. i'm not that good at java... we got this CA in class and try as i might i just can't get my head around it
    i was wondering if someone who know a bit more about java then i do would point me in the right direction, were i'm going wrong in my code
    i have to list out sub-files and sub-directorys of a folder (i.e. C:/test) to console using tree structure
    like this
    startingdir
    dir1 //subfolder of startingdir
    dir11 //subfolder of dir1
    dir111 //subfolder of dir11
    dir12 //subfolder of dir1
    file1A // document on dir1
    dir2 //subfolder of startingdir
    Tree.java
    import java.util.Iterator;
    import java.util.LinkedList;
    import java.util.ListIterator;
    import java.util.NoSuchElementException;
    import java.util.Deque;
    public class Tree<E> {
        // Each Tree object is an unordered tree whose
        // elements are arbitrary objects of type E.
        // This tree is represented by a reference to its root node (root), which
        // is null if the tree is empty. Each tree node contains a link to its
        // parent and a LinkedList of child nodes
        private Node root;
        //////////// Constructor ////////////
        public Tree () {
        // Construct a tree, initially empty.
            root = null;
        //////////// Accessors ////////////
        public boolean isEmpty () {
        // Return true is and only if this tree is empty.
             return (root == null);
        public Node root () {
        // Return the root node of this tree, or null if this tree is empty.
            return root;
        public Node parent (Node node) {
        // Return the parent of node in this tree, or null if node is the root node.
            return node.parent;
        public void makeRoot (E elem) {
        // Make this tree consist of just a root node containing element elem.
            root = new Node(elem);
        public Node addChild (Node node, E elem) {
        // Add a new node containing element elem as a child of node in this
        // tree. The new node has no children of its own. Return the node
        // just added.
            Node newChild = new Node(elem);
            newChild.parent = node;
            node.children.addLast(newChild);
            return newChild;
        public E element (Node node) {
             return node.getElement();
        //////////// Iterators ////////////
        public Iterator childrenIterator (Node node) {
            return node.children.iterator();
        public Iterator nodesPreOrder () {
        // Return an iterator that visits all nodes of this tree, with a pre-order
        // traversal.
            return new Tree.PreOrderIterator();
        //////////// Inner classes ////////////
        public class Node {
            // Each Tree.Node object is a  node of an
            // unordered tree, and contains a single element.
            // This tree node consists of an element (element),
            // a link to its parent
            // and a LinkedList of its children
            private E element;
            private Node parent;
            private LinkedList<Node> children;
            private Node (E elem) {
                // Construct a tree node, containing element elem, that has no
                // children and no parent.
                this.element = elem;
                this.parent = null;
                children = new LinkedList<Node>();
            public E getElement () {
            // Return the element contained in this node.
                return this.element;
            public String toString () {
            // Convert this tree node and all its children to a string.
                String children = "";
                // write code here to add all children
                return element.toString() + children;
            public void setElement (E elem) {
            // Change the element contained in this node to be elem.
                this.element = elem;
        public class PreOrderIterator implements Iterator {
            private Deque<Node> track; //Java recommends using Deque rather
            // than Stack. This is used to store sequence of nomempty subtrees still
            //to be visited
            private PreOrderIterator () {
                track = new LinkedList();
                if (root != null)
                    track.addFirst(root);
            public boolean hasNext () {
                return (! track.isEmpty());
            public E next () {
                Node place = track.removeFirst();
                //stack the children in reverse order
                if (!place.children.isEmpty()) {
                    int size = place.children.size(); //number of children
                    ListIterator<Node> lIter =
                            place.children.listIterator(size); //start iterator at last child
                    while (lIter.hasPrevious()) {
                        Node element = lIter.previous();
                        track.addFirst(element);
                return place.element;
            public void remove () {
                throw new UnsupportedOperationException();
        FileHierarchy.java
    import java.io.File;
    import java.util.Iterator;
    public class FileHierarchy {
        // Each FileHierarchy object describes a hierarchical collection of
        // documents and folders, in which a folder may contain any number of
        // documents and other folders. Within a given folder, all documents and
        // folders have different names.
        // This file hierarchy is represented by a tree, fileTree, whose elements
        // are Descriptor objects.
        private Tree fileTree;
        //////////// Constructor ////////////
        public FileHierarchy (String startingDir, int level) {
            // Construct a file hierarchy with level levels, starting at
            // startingDir
            // Can initially ignore level and construct as many levels as exist
            fileTree = new Tree();
            Descriptor descr = new Descriptor(startingDir, true);
            fileTree.makeRoot(descr);
            int currentLevel = 0;
            int maxLevel = level;
            addSubDirs(fileTree.root(), currentLevel, maxLevel);
        //////////// File hierarchy operations ////////////
        private void addSubDirs(Tree.Node currentNode, int currentLevel,
                int maxLevel) {
        // get name of directory in currentNode
        // then find its subdirectories (can add files later)
        // for each subdirectory:
        //    add it to children of currentNode - call addChild method of Tree
        //    call this method recursively on each child node representing a subdir
        // can initially ignore currentLevel and maxLevel   
            Descriptor descr = (Descriptor) currentNode.getElement();
            File f = new File(descr.name);
            File[] list = f.listFiles();
            for (int i = 0; i < list.length; ++i) {
                if (list.isDirectory()) {
    File[] listx = null;
    fileTree.addChild(currentNode, i);
    if (list[i].list().length != 0) {
    listx = list[1].listFiles();
    addSubDirs(currentNode,i,1);
    } else if (list[i].isFile()) {
    fileTree.addChild(currentNode, i);
    // The following code is sample code to illustrate how File class is
    // used to get a list of subdirectories from a starting directory
    // list now contains subdirs and files
    // contained in dir descr.name
    ////////// Inner class for document/folder descriptors. //////////
    private static class Descriptor {
    // Each Descriptor object describes a document or folder.
    private String name;
    private boolean isFolder;
    private Descriptor (String name, boolean isFolder) {
    this.name = name;
    this.isFolder = isFolder;
    FileHierarchyTest.javapublic class FileHierarchyTest {
    private static Tree fileTree;
    public static void main(String[] args) {
    FileHierarchy test = new FileHierarchy ("//test", 1);
    System.out.println(test.toString());

    Denis,
    Do you have [red hair|http://www.dennisthemenace.com/]? ;-)
    My advise with the tree structure is pretty short and sweet... make each node remember
    1. it's parent
    2. it's children
    That's how the file system (inode) actually works.
    <quote>
    The exact reasoning for designating these as "i" nodes is unsure. When asked, Unix pioneer Dennis Ritchie replied:[citation needed]
    In truth, I don't know either. It was just a term that we started to use. "Index" is my best guess, because of the
    slightly unusual file system structure that stored the access information of files as a flat array on the disk, with all
    the hierarchical directory information living aside from this. Thus the i-number is an index in this array, the
    i-node is the selected element of the array. (The "i-" notation was used in the 1st edition manual; its hyphen
    became gradually dropped).</quote>

  • Tree Structure in Active Directory

    Hi,
    I am trying ot come up with a design of some sort if generic LDAP connector different LDAP servers. So far I have been just testing against Active Directory and OpenLDAP.
    I know there are numerous implementations out there but the difference in features between these two itself have made the design difficult.
    I had a question in regards to the way the data is organized in Active Directory as opposed to OpenLDAP.
    In active directory you can have an
    OU
    CN {person}
    CN{group}
    Now users under different OU's can have access to other OU's I figure by belonging to the CN{group } under that OU . But the same user can't exists under two different OU's with the exact same attribute values. Is my understanding right??
    Now when I used this OpenLDAP Windows version I could very easily create the same user under two different OU's.
    Further on in Active Directory you have something called the objectGUID to get to the entry even if it is moved around in the tree casue at one point it can exists in only one place. Is this understanding right??
    What happens in case of an OpenLDAP how do we get the unique id?
    Please help

    tigerkumar wrote:
    HI
    I am using swing on that JPanel
    and
    i got the drives of system in my combo box
    can u tell me how to show selected drive`s folders in a tree structure
    using JTree
    how i can show the the directories(folder`s) of a drive into the JTree box
    directory to be selected from ComboBox showing driveswhat is wrong with you?
    why keep on multi-posting, I give you a solution and you ignore it.
    http://forum.java.sun.com/thread.jspa?threadID=5217925&tstart=0
    no one will help you if you keep on doing that.

  • Multi-selection using windows style tree structure

    We developed a solution to replace the standard multi-select functionality with a java based tree structure where upon selection of a node all sub-entries are selected.  These entries are then added to the selection.
    Performance is however a problem and I would like to know if anyone has experience of implementing such a solution or if there is an alternative standard solution. 
    regards
    Tim

    Hello Tim,
    Did you try to run an SE30 performance analysis ?
    Check out this OSS note:
    Note 948066 - Performance Analysis: Transactions to use
    And depending on your CRM version, be aware that you can use the ABAP shared memory concept, which will considerably reduce the amount of memory used... hence increasing performance.
    Ciao,
    Nicolas.

  • General tree structure

    Is there still no general tree structure in Java? I'd like something along the likes of TreeSet or TreeMap, but without the compare part, and where each node can hold 0..n children.
    I know this is easy to implement, having done quite a few during my student years, but if any of the API classes are able to handle it directly, I'd sure like to know.
    Does anyone know of any fitting classes?

    Maybe you can use DefaultMutableTreeNode. It's a general tree class of Swing.
    Or why not encode the tree structure in a key. Say you have up to 10 mother companies each having up to 10 daugthers. You can code these 100 companies as numbers between 0 and 99. For example 52 would be the second daughter of the fifth mother, etcetera. Then you just keep the objects sorted on key in an ArrayList or maybe use a HashMap depending on your searching needs.

  • How to get Text for nodes in Tree Structure

    Hi Friends,
    How to get Text for nodes in Tree Structure
    REPORT  YFIIN_REP_TREE_STRUCTURE  no standard page heading.
                       I N I T I A L I Z A T I O N
    INITIALIZATION.
    AUTHORITY-CHECK OBJECT 'ZPRCHK_NEW' :
                      ID 'YFIINICD' FIELD SY-TCODE.
      IF SY-SUBRC NE 0.
        MESSAGE I000(yFI02) with SY-TCODE .
        LEAVE PROGRAM.
      ENDIF.
    class screen_init definition create private.
    Public section
      public section.
        class-methods init_screen.
        methods constructor.
    Private section
      private section.
        data: container1 type ref to cl_gui_custom_container,
              container2 type ref to cl_gui_custom_container,
              tree type ref to cl_gui_simple_tree.
        methods: fill_tree.
    endclass.
    Class for Handling Events
    class screen_handler definition.
    Public section
      public section.
        methods: constructor importing container
                   type ref to cl_gui_custom_container,
                 handle_node_double_click
                   for event node_double_click
                   of cl_gui_simple_tree
                   importing node_key .
    Private section
      private section.
    endclass.
    *&                        Classes implementation
    class screen_init implementation.
    *&                        Method INIT_SCREEN
      method init_screen.
        data screen type ref to screen_init.
        create object screen.
      endmethod.
    *&                        Method CONSTRUCTOR
      method constructor.
        data: events type cntl_simple_events,
              event like line of events,
              event_handler type ref to screen_handler.
        create object: container1 exporting container_name = 'CUSTOM_1',
                       tree exporting parent = container1
                         node_selection_mode =
                cl_gui_simple_tree=>node_sel_mode_multiple.
        create object: container2 exporting container_name = 'CUSTOM_2',
        event_handler exporting container = container2.
    event-eventid = cl_gui_simple_tree=>eventid_node_double_click.
        event-appl_event = ' '.   "system event, does not trigger PAI
        append event to events.
        call method tree->set_registered_events
             exporting events = events.
        set handler event_handler->handle_node_double_click for tree.
         call method: me->fill_tree.
      endmethod.
    *&                        Method FILL_TREE
      method fill_tree.
        data: node_table type table of abdemonode,
              node type abdemonode.
    types:    begin of tree_node,
              folder(50) type c,
              tcode(60) type c,
              tcode1(60) type c,
              tcode2(60) type c,
              text(60) type c,
              text1(60) type c,
              text2(60) type c,
              end of tree_node.
      data:  wa_tree_node type tree_node,
                t_tree_node type table of tree_node.
    wa_tree_node-folder = text-001.
    wa_tree_node-tcode  = text-002.
    wa_tree_node-text =  'Creditors ageing'.
    wa_tree_node-tcode1 = text-003.
    wa_tree_node-text1 =  'GR/IR aging'.
    wa_tree_node-tcode2 = text-004.
    wa_tree_node-text2 =  'Bank Balance'.
    append wa_tree_node to t_tree_node.
    clear wa_tree_node .
    wa_tree_node-folder = text-005.
    wa_tree_node-tcode  = text-006.
    wa_tree_node-text =  'Creditors ageing'.
    wa_tree_node-tcode1 = text-007.
    wa_tree_node-text1 =  'Creditors ageing'.
    wa_tree_node-tcode2 = text-008.
    wa_tree_node-text2 =  'Creditors ageing'.
    append wa_tree_node to t_tree_node.
    clear wa_tree_node .
    wa_tree_node-folder = text-009.
    wa_tree_node-tcode  = text-010.
    wa_tree_node-text =  'Creditors ageing'.
    wa_tree_node-tcode1 = text-011.
    wa_tree_node-text1 =  'Creditors ageing'.
    wa_tree_node-tcode2 = text-012.
    wa_tree_node-text2 =  'Creditors ageing'.
    append wa_tree_node to t_tree_node.
    clear wa_tree_node .
    node-hidden = ' '.                 " All nodes are visible,
        node-disabled = ' '.               " selectable,
        node-isfolder = 'X'.                                    " a folder,
        node-expander = ' '.               " have no '+' sign forexpansion.
        loop at t_tree_node into wa_tree_node.
          at new folder.
            node-isfolder = 'X'.                      " a folder,
            node-node_key = wa_tree_node-folder.
                   clear node-relatkey.
            clear node-relatship.
            node-text = wa_tree_node-folder.
            node-n_image =   ' '.
            node-exp_image = ' '.
            append node to node_table.
          endat.
         at new tcode .
            node-isfolder = ' '.                          " a folder,
            node-n_image =   '@CS@'.       "AV is the internal code
            node-exp_image = '@CS@'.       "for an airplane icon
            node-node_key = wa_tree_node-tcode.
             node-text = wa_tree_node-text .
                     node-relatkey = wa_tree_node-folder.
            node-relatship = cl_gui_simple_tree=>relat_last_child.
          endat.
          append node to node_table.
        at new tcode1 .
            node-isfolder = ' '.                          " a folder,
            node-n_image =   '@CS@'.       "AV is the internal code
            node-exp_image = '@CS@'.       "for an airplane icon
            node-node_key = wa_tree_node-tcode1.
                     node-relatkey = wa_tree_node-folder.
            node-relatship = cl_gui_simple_tree=>relat_last_child.
              node-text = wa_tree_node-text1.
         endat.
          append node to node_table.
           at new tcode2 .
            node-isfolder = ' '.                          " a folder,
            node-n_image =   '@CS@'.       "AV is the internal code
            node-exp_image = '@CS@'.       "for an airplane icon
            node-node_key = wa_tree_node-tcode2.
                     node-relatkey = wa_tree_node-folder.
            node-relatship = cl_gui_simple_tree=>relat_last_child.
            node-text = wa_tree_node-text2.
         endat.
          append node to node_table.
        endloop.
        call method tree->add_nodes
             exporting table_structure_name = 'ABDEMONODE'
                       node_table = node_table.
      endmethod.
    endclass.
    *&                        Class implementation
    class screen_handler implementation.
    *&                        Method CONSTRUCTOR
      method constructor.
       create object: HTML_VIEWER exporting PARENT = CONTAINER,
                      LIST_VIEWER exporting I_PARENT = CONTAINER.
      endmethod.
    *&                 Method HANDLE_NODE_DOUBLE_CLICK
      method handle_node_double_click.
      case node_key(12).
    when 'Creditors'.
    submit YFIIN_REP_CREADITORS_AGING  via selection-screen and return.
    when  'Vendor'.
    submit YFIIN_REP_VENDOR_OUTSTANDING  via selection-screen and return.
    when 'Customer'.
    submit YFIIN_REP_CUSTOMER_OUTSTANDING  via selection-screen and
    return.
    when 'GR/IR'.
    submit YFIIN_REP_GRIR_AGING  via selection-screen and return.
    when 'Acc_Doc_List'.
    submit YFIIN_REP_ACCOUNTINGDOCLIST  via selection-screen and return.
    when 'Bank Bal'.
    submit YFIIN_REP_BANKBALANCE  via selection-screen and return.
    when 'Ven_Cus_Dtl'.
    submit YFIIN_REP_VENDORCUST_DETAIL via selection-screen and return.
    when 'G/L_Open_Bal'.
    submit YFIIN_REP_OPENINGBALANCE via selection-screen and return.
    when 'Usr_Authn'.
    submit YFIIN_REP_USERAUTHRIZATION via selection-screen and return.
    endcase.
      endmethod.
    endclass.
    Program execution ************************************************
    load-of-program.
      call screen 9001.
    at selection-screen.
    Dialog Modules PBO
    *&      Module  STATUS_9001  OUTPUT
          text
    module status_9001 output.
      set pf-status 'SCREEN_9001'.
      set titlebar 'TIT_9001'.
      call method screen_init=>init_screen.
    endmodule.                 " STATUS_9001  OUTPUT
    Dialog Modules PAI
    *&      Module  USER_COMMAND_9001  INPUT
          text
    module user_command_9001 input.
    endmodule.                 " USER_COMMAND_9001  INPUT
    *&      Module  exit_9001  INPUT
          text
    module exit_9001 input.
    case sy-ucomm.
    when 'EXIT'.
      set screen 0.
    endcase.
    endmodule.
            exit_9001  INPUT

    you can read  the table node_table with nody key value which imports when docubble click the the tree node (Double clifk event).
    Regards,
    Gopi .
    Reward points if helpfull.

  • How to create Tree structure in Visual Composer

    Hi All,
         I need to develop tree structure in my VC application. Can any one of you please suggest me the steps to do it.Its very urgent please can any one help me out in this.
    Regards,
    Lakshmi

    Hi Nutan,
    if you want to solve it with webdynpro it depends on your skills in java and abap. There are books available to start with webdynpro and there are examples for building tree structures with Webdynpro.
    [Java Webdynpro|http://www.sappress.com/product.cfm?account=&product=H983]
    [ABAP Webdynpro|http://www.sappress.com/product.cfm?account=&product=H1916]
    If you want to do it in VC you have to write e.g. an ABAP rfc function module, which returns you the tree with the information about childnode, parentnode and so on, so that you can display it in the table. But if the users click on sort then the tree is "destroyed". You can also display only a few levels of your tree and when you select a certain node a drill down is done by calling a rfc which returns the child nodes of the corresponding node.
    But I think the solution with VC is not the best. Use webdynpro for this requirements.
    Best Regards,
    Marcel

  • t:tree component is not rendering tree structure for my page

    Dear dudes,
    I want to create a simple tree structure in my jsf page backed by a backing bean.
    But my jsf page is getting executed but my tree is not getting displayed.
    my jsf page:<ui:composition xmlns="http://www.w3.org/1999/xhtml"
         xmlns:ui="http://java.sun.com/jsf/facelets"
         xmlns:h="http://java.sun.com/jsf/html"
         xmlns:f="http://java.sun.com/jsf/core"
         xmlns:s="http://jboss.com/products/seam/taglib"
         xmlns:rich="http://richfaces.ajax4jsf.org/rich"
         xmlns:t="http://myfaces.apache.org/tomahawk"
         xmlns:a4j="https://ajax4jsf.dev.java.net/ajax">
    <f:view>
         <html>
              <body>
                   <h:form>
                        <t:tree id="tree" value="#{mytreeBean.myTree}" styleClass="tree"
                             nodeClass="treenode" selectedNodeClass="treenodeSelected"
                             >
                        </t:tree>
                   </h:form>
              </body>
         </html>
    </f:view>
    </ui:composition>Mybacking bean:
    package org.test.tree;
    import java.util.Iterator;
    import java.util.List;
    import org.apache.myfaces.custom.tree.DefaultMutableTreeNode;
    import org.apache.myfaces.custom.tree.model.DefaultTreeModel;
    import com.srit.framework.web.BasePage;
    import com.srit.healthcare.common.lookupentity.repository.ILookupRepository;
    import com.srit.healthcare.common.tree.domain.RcareTree;
    public class MyTreebean {
         private DefaultTreeModel myTree;
         public DefaultTreeModel getMyTree() {
              return myTree=getTreeModel();
         public void setMyTree(DefaultTreeModel myTree) {
              this.myTree = myTree;
         /*public MyTreebean() {
              DefaultMutableTreeNode root = new DefaultMutableTreeNode("XY");
              DefaultMutableTreeNode a = new DefaultMutableTreeNode("A");
              root.insert(a);
              DefaultMutableTreeNode b = new DefaultMutableTreeNode("B");
              root.insert(b);
              DefaultMutableTreeNode c = new DefaultMutableTreeNode("C");
              root.insert(c);
              DefaultMutableTreeNode node = new DefaultMutableTreeNode("a1");
              a.insert(node);
              node = new DefaultMutableTreeNode("a2 ");
              a.insert(node);
              node = new DefaultMutableTreeNode("b ");
              b.insert(node);
              a = node;
              node = new DefaultMutableTreeNode("x1");
              a.insert(node);
              node = new DefaultMutableTreeNode("x2");
              a.insert(node);
              myTree = new DefaultTreeModel(root);
         public DefaultTreeModel getTreeModel() {
              DefaultMutableTreeNode root = new DefaultMutableTreeNode("XY");
              DefaultMutableTreeNode a = new DefaultMutableTreeNode("A");
              root.insert(a);
              DefaultMutableTreeNode b = new DefaultMutableTreeNode("B");
              root.insert(b);
              DefaultMutableTreeNode c = new DefaultMutableTreeNode("C");
              root.insert(c);
              DefaultMutableTreeNode node = new DefaultMutableTreeNode("a1");
              a.insert(node);
              node = new DefaultMutableTreeNode("a2 ");
              a.insert(node);
              node = new DefaultMutableTreeNode("b ");
              b.insert(node);
              a = node;
              node = new DefaultMutableTreeNode("x1");
              a.insert(node);
              node = new DefaultMutableTreeNode("x2");
              a.insert(node);
              return myTree = new DefaultTreeModel(root);
    }Also i've configured my tomahawk-taglib file in my web.xml .
    My backing bean is configured in my faces-config.xml
    But i'm not able to get my tree structure in my page .
    Any help would be appreciated.
    Regards

    Dear akash,
    yes i'm seeing the jsf tags <t:tree>
    But when i modify my jsf page , in my configuration files i'm getting the following errors:
    In web.xml
    <web-app xmlns="http://java.sun.com/xml/ns/j2ee"
         xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
         xsi:schemaLocation="http://java.sun.com/xml/ns/j2ee http://java.sun.com/xml/ns/j2ee/web-app_2_4.xsd"
         version="2.4">
    </web-app>
    error message:  cannot find the declaration of element web-apps
    error message: failed to read schema document http://java.sun.com/xml/ns/j2ee             http://java.sun.com/xml/ns/j2ee/web-app_2_4.xsd  because 1) couldnot find the document 2) the document could not be read 3) the root element of the document is not <xsd:schema>In another configuration file:
    <?xml version="1.0" encoding="UTF-8"?>
    <beans xmlns="http://www.springframework.org/schema/beans"
         xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
         xmlns:aop="http://www.springframework.org/schema/aop"
         xmlns:tx="http://www.springframework.org/schema/tx"
         xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-2.0.xsd
                http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop-2.0.xsd
                http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-2.0.xsd">
    Error: cannot find the declaration of element 'beans'I'm a novice to JSF technology and plz guide me properly.

  • How to Show floders and documents as a tree structure from path only

    sir,
    I am doing system side project using Java..
    so i want to know how to show folders and documents as tree structure format..
    plz give your idea regarding this?

    See for example Tree taglib in Coldtags suite:
    http://www.servletsuite.com/jsp.htm

  • Tree structure of portal application in NWDS

    Hi all,
    Im new to portal applications and I did not under stand the tree structure that appears after we start portal application in ep perspective in NWDS. Especially the PORTAL-INF and src.code in the tree structure .If any body has any relevant information or document about it please send me.

    portal applications are same as the Web applications developed in Java, JSP ....
    PORTAL-INF is same as the WEB-INF in normal web application structure.
    in Web application we create .war file whereas here we create as .par file.
    in web application we have web.xml inside WEB-INF folder where as here we have portalapp.xml.
    src.core and src.api is used as the source code folder.
    You can check this in "Java Build path" if u go to the project properties.
    Hope this give u a small idea on portal files structure.
    cheers.
    Chinmaya
    Reward points for hellpful answers.

  • To get the tree structure using html

    how to get tree structure using html?is there any commands in html to get the tree structure

    This is a Java forum, not HTML.

  • Org Chart in tree structure

    Hi Friends,
    How to Create a tree structure  for org. unit in  web dynpro ABAP
    and call the tree in F4 Help of a input box.

    Good advice there guys.
    I myself just finished such an implementation at one of my customers. It took 2 days to complete. I can't give you the solution as the customer retains the immaterial rights for the solution but I thought I would tell you the steps involved to get you on the right track.
    1. Context. Build a context node that on the top level has the orgunit, it's attributes (such as otype, objid, stext, etc) and the recursive node that points to the orgunit node. Inside the orgunit create a node for the position. Inside the node place the attributes for the position (like before) and a recursive node that points to the position node. Finally inside the position node place a node for the person and it's attributes (like before), but no recursion node this time.
    2. Layout: Place a tree element in your view. Inside the tree element insert two node types and one item type. First node is for orgunit, second one is for position. The only item is for the person. You might want to add respective icons, to get nicer UI. Add the load children action for orgunit and position. Depending on what you want to select from the tree, add a select action for either orgunit, position or person.
    3. Code #1: as Chris points out, use RH_STRUC_GET to get the organization tree. I myself used O_S_P. You might want to create a FM that returns all 3 itabs returned by RH_STRUC_GET to the WDA. Create a freely programmed value help as suggested in many threads, it's pretty straight forward. In the WDA utilizing the VH, mark one or more items in the context as freely programmed VH and connect to your implementation.
    4. Code #2: At start up, for example in the WDDOINIT method, create only the root node and call it for example "All organization units". Then create one action that is called when children nodes have to be loaded, one method for figuring out what do when a child is being requested (and what kind of child: orgunit, position or person) and finally a method for actually creating the node.
    5. Code #3: The magic comes from RH_STRUC_GET. Use the STRUC itab at runtime to find the objects at certain levels and to determine their parent(s) and children. The most important values in the STRUC itab in this case are LEVEL, OTYPE, OBJID and PUP.
    Pretty straight forward and the solution is quite nice indeed. I'm sorry if I forgot something, I wrote this without access to the system.

Maybe you are looking for