Problem with Dynamic tree using struts

Help
2006-06-28
2013-03-22
  • Sridhar Bakkawad

    hi,
    I am building a dynamic tree using stuts...
    As people stated, i have overriden a buildTree()
    method in TestFactory class as..

    private TreeStructureModel buildTree() {
       TreeStructureModel a_tree = new TreeModel();
      
        try{
              traverse(a_tree,new File("C:/NewFolder"));
        }catch(IOException ioe){ }
            return a_tree;
    }

    ...here i am giving a folder name as 
      new File("C:/NewFolder") to "traverse" method as shown , which read the contents of the folder and sets a tree root, parent and child parameters accordingly ....
    and thereby generating a tree as per the contents of the folder....
    its working fine....but when i change the contents of the folder and do refresh, changes are  not reflecting in my tree...
    Instead when i restart the server than only changes are reflecting!!!  Why so?

    Also, here im doing without using xml tree...

    I am setting

    a_component.setTreeFactory(new TestFactory());

    in TestServlet class
      
    Plz do the needful...
    Thanx....

     
    • Vladislav

      Vladislav - 2006-07-03

      >but when i change the contents of the folder and do refresh, changes are not reflecting in my tree...

      Each time you need to refresh your tree just wipe tree's cache off:

      //get HttpSession
      session.removeAttribute(JSPTreeComponent.JSP_TREE_CACHE + "-" + TREE_NAME);

      Thanks,
      Vlad.

       
    • kris

      kris - 2008-04-06

      Hi Vlad/ Sridhar,
           I need your help in displaying the tree structre in the JSP. I just get a blank page without any errors. Here are the settings and the code snippet I have written to display the tree structure dynamically. Please let me know, in case I have missed any thing. Thanks in advance.

      web.xml configuration:
      ----------------------
      <taglib>
                 <taglib-uri>/WEB-INF/jsptree.tld</taglib-uri>
                 <taglib-location>/WEB-INF/jsptree.tld</taglib-location>
      </taglib>

      I have copied the jsptree.tld under /WEB-INF/ folder of Tomcat 5.5.29

      TestFacatory.java:
      ------------------

      package com.ui.business;

      import net.sf.jsptree.component.JSPTreeNodeImpl;
      import net.sf.jsptree.tree.*;

      public class TestFactory implements TreeFactory {

          public TestFactory() {
          }

          public TreeFactory getInstance() {
              TreeFactory m_instance = new TestFactory();
              System.out.println("Inside TestFactory.getInstance()");
              return m_instance;
          }

          /**
           * Returns new <code>Tree</code> instance by its name.
           *
           * @param p_name The name of the tree to be built.
           */
          public TreeStructureModel getTree(String p_name) {
              System.out.println("Inside TestFactory.getTree()");
              return buildTree();

          }

          private TreeStructureModel buildTree() {
              TreeStructureModel a_tree = new TreeModel();
              //TODO
              //a_tree.setComparator(new JSPTreeNodeComparatorImpl());

              a_tree.setRoot(new JSPTreeNodeImpl("1", "NODE1"));
              a_tree.addChildToRoot(new JSPTreeNodeImpl("2", "NODE2"));
              a_tree.addChildToRoot(new JSPTreeNodeImpl("3", "NODE3"));

              a_tree.addChildToRoot(new JSPTreeNodeImpl("4", "NODE4"));
              a_tree.addChildToParent(new JSPTreeNodeImpl("4"), new JSPTreeNodeImpl("10", "NODE10"));

              a_tree.addChildToRoot(new JSPTreeNodeImpl("5", "NODE5"));

              a_tree.addChildToParent(new JSPTreeNodeImpl("5"), new JSPTreeNodeImpl("7", "NODE7"));
              a_tree.addChildToParent(new JSPTreeNodeImpl("5"), new JSPTreeNodeImpl("8", "NODE8"));

              a_tree.addChildToParent(new JSPTreeNodeImpl("7"), new JSPTreeNodeImpl("6", "NODE6"));

              a_tree.addChildToParent(new JSPTreeNodeImpl("6"), new JSPTreeNodeImpl("11", "NODE     11"));

              a_tree.addChildToParent(new JSPTreeNodeImpl("11"), new JSPTreeNodeImpl("12", "NODE    12"));

              a_tree.addChildToParent(new JSPTreeNodeImpl("12"), new JSPTreeNodeImpl("13", "NODE    13"));

              a_tree.addChildToParent(new JSPTreeNodeImpl("13"), new JSPTreeNodeImpl("14", "NODE    14"));

              a_tree.addChildToParent(new JSPTreeNodeImpl("8"), new JSPTreeNodeImpl("15", "NODE15"));

              a_tree.addChildToParent(new JSPTreeNodeImpl("8"), new JSPTreeNodeImpl("16", "NODE16"));

              a_tree.addChildToParent(new JSPTreeNodeImpl("16"), new JSPTreeNodeImpl("18", "NODE18"));

              JSPTreeNodeImpl a_node19 = new JSPTreeNodeImpl("19", "JSPTREE");

              a_node19.setHref("http://jsptree.sourceforge.net");
              a_node19.setContextRelative(false);
              a_tree.addChildToParent(new JSPTreeNodeImpl("16"), a_node19);

              JSPTreeNodeImpl a_node17 = new JSPTreeNodeImpl("17", "NODE17");
              a_tree.addChildToParent(new JSPTreeNodeImpl("8"), a_node17);

              System.out.println("Inside TestFactory.buildTree()");
              return a_tree;
          }

          public TreeStateModel getTreeStates(String p_name) throws TreeFactoryException {
              DefaultTreeStateModel defaultTreeStateModel = new DefaultTreeStateModel();
              defaultTreeStateModel.addOpened(new JSPTreeNodeImpl("1").hashCode());
              defaultTreeStateModel.addOpened(new JSPTreeNodeImpl("4").hashCode());
              defaultTreeStateModel.addOpened(new JSPTreeNodeImpl("5").hashCode());

              return defaultTreeStateModel;
          }
      }

      Last in the JSP I have the following code:
      ------------------------------------------

      <TABLE WIDTH="100%">
          <TR>
              <TD>Search Result Menu Page</TD>
          </TR>
          <TR>
              <TD>
              <table cellpadding=0 cellspacing=0>
                  <tr>
                      <td>
                      <%
                          net.sf.jsptree.tree.TreeFactory treeFactory = new com.eai.spls.router.ui.business.TestFactory().getInstance();
                         
                          String imagePath     = request.getContextPath()+"/images/tree/menu/dark-blue/";
                          // String xtreePath     = request.getContextPath()+"/WEB-INF/xmlTree.xml";
                          String templatePath = request.getContextPath()+"/WEB-INF/template/menu/";
                      %>
                      <jspTree:JSPTree name="demoTree"
                          treeFactory="<%=treeFactory%>"
                          startAtDepth="0"
                          imagesPath="<%=imagePath%>"
                          templatePath="<%=templatePath%>"
                          shareTreeStructure="true"
                          skin="<%=AbstractSkin.DEFAULT_SKIN%>"
                          />
                      </td>
                  </tr>
              </table>
              </TD>
          </TR>
      </TABLE>

           Last but not least I have copied the necessary jar files into the Tomcat lib directory (I do not get any classapth error). can you please tell me if I have missed any thing that is preventing me to see the tree structure output.

           Your timely help is very much appreciated.

      Thanks,
      Kris

       

Log in to post a comment.

Get latest updates about Open Source Projects, Conferences and News.

Sign up for the SourceForge newsletter:

JavaScript is required for this form.





No, thanks