Win a copy of Re-engineering Legacy Software this week in the Refactoring forum
or Docker in Action in the Cloud/Virtualization forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Convert nested Java Object to tree structure

 
Dilip H Pashupathi
Ranch Hand
Posts: 52
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,

I have a requirement where I need to create a tree structure using a nested java object. For this I have class called CustomNode where names of each node will be stored in a variable and child node will be stored as object inside this



This is the portion of the code that will be used to create the nested object for tree representations. I am locking for a logic to convert this into a tree structure similar to folder tree in winodws explorer. Once the tree is created i need to display that in a jsp page in the web application. This tree needs to be dynamic in nature as user is allowed to add, delete or update the details of the node as and when required, and each node is stored as a tag in the database under some table.

And each node that is being added comes from the database tables itself.

Thanks and regards
Dilip
 
E Armitage
Rancher
Posts: 989
9
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
So at which point exactly are you stuck?
 
Dilip H Pashupathi
Ranch Hand
Posts: 52
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,

I was using MenuComponent from Struts framework. Adding is simple. but deleting and updating becomes a problem. Since entire thing is supposed to dynamic in nature

 
Joe Ess
Bartender
Pie
Posts: 9259
10
Linux Mac OS X Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Dilip H Pashupathi wrote:Hi,
I was using MenuComponent from Struts framework.

There is no MenuComponent class in the Struts API. Are you still trying to use Struts Layout?
 
Jayesh A Lalwani
Rancher
Posts: 2756
32
Eclipse IDE Spring Tomcat Server
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I'm not sure what you are asking here.

Are you asking how to populate the MenuComponent from StrutsLayout? I am pretty sure that not many people will have used an obscure third party library that has been dead for 2+ years

Are you asking us how you could render a tree on the web page? There are plenty of solutions available. Jquery provides a tree control. You can start from that.
 
Dilip H Pashupathi
Ranch Hand
Posts: 52
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,

@Joe:
Yes I was using struts layout for showing the tree.

@Jayesh:
Yes I am trying to render a tree on the web page.

But this is dynamic in nature. What we are trying to achieve is there is a table called AGX_XML_SCHEMA_DEFINITION where the tags are stored as rows. having parent and child relation ship. This table is intern represented in the Java code as CustomNode class. I am able to retrieve the tags from this table and fom it into a nested object using the CustomNode class. But represent this in a tree structure in JSP I was using the MenuComponent "fr.improve.struts.taglib.layout.menu.MenuComponent".

This is available in Struts Layout API. Even I am able to get the tree view displayed on the JSP page using


The tag above is used to display the tree.



The above code is used to get the tree and put it into the session so that i will be able to access the tree in JSP.

Problem with this menu component is adding, deleting, updating the tree dynamically.



The above code explains how the tree is constructed.

Any help would be appreciated.

Thanks and Regards.
Dilip
 
Joe Ess
Bartender
Pie
Posts: 9259
10
Linux Mac OS X Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Dilip H Pashupathi wrote:
Problem with this menu component is adding, deleting, updating the tree dynamically.


By "dynamically", do you mean you want to update the tree without reloading the page? I don't know that that is possible with the library you have chosen. I'd again recommend jQuery.
If you mean you want to submit a change and reload the page, what is your specific question? Working with the tree data structure?
 
Dilip H Pashupathi
Ranch Hand
Posts: 52
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Joe,

I have attached a screen shot for the tree generation. Both of them are created with AJAX calls. But problem here is I am able to remove the tag from tree by clicking delete button. But it only deletes the nested object from CustomNode class, but not the tree itself. I tried using removeMenuComponent() method from MenuComponent class. But it doesn't work. But since I do not have sufficient knowledge on JQuery, I am unable to use that.

Thanks and Regards
Dilip
Tree1.png
This is the screen shot of Adding a tag to the tree.
[Thumbnail for Tree1.png]
Tree2.png
This is the screen shot having node details, and a delete button to delete the node from tree.
[Thumbnail for Tree2.png]
 
Joe Ess
Bartender
Pie
Posts: 9259
10
Linux Mac OS X Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
So you change the data structure on the server side (which you did not share the code for, I may add. all we know of your situation is what you've told us). How do you propose to inform the static HTML on the client side? You will probably have to reload that pane if Struts Layout does not support AJAX.
 
Dilip H Pashupathi
Ranch Hand
Posts: 52
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Joe,

Sorry for the missed information. Code that I shared is actually the one which creates and adds node to the root. Here is the code that creates the complete tree structure.





 
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic