aspose file tools*
The moose likes Struts and the fly likes Convert nested Java Object to tree structure Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Spring in Action this week in the Spring forum!
JavaRanch » Java Forums » Frameworks » Struts
Bookmark "Convert nested Java Object to tree structure" Watch "Convert nested Java Object to tree structure" New topic
Author

Convert nested Java Object to tree structure

Dilip H Pashupathi
Ranch Hand

Joined: Jul 24, 2013
Posts: 35
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

Joined: Mar 17, 2012
Posts: 892
    
    9
So at which point exactly are you stuck?
Dilip H Pashupathi
Ranch Hand

Joined: Jul 24, 2013
Posts: 35
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

Joined: Oct 29, 2001
Posts: 8927
    
    9

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?


"blabbing like a narcissistic fool with a superiority complex" ~ N.A.
[How To Ask Questions On JavaRanch]
Jayesh A Lalwani
Bartender

Joined: Jan 17, 2008
Posts: 2404
    
  28

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

Joined: Jul 24, 2013
Posts: 35
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

Joined: Oct 29, 2001
Posts: 8927
    
    9

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

Joined: Jul 24, 2013
Posts: 35
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



[Thumbnail for Tree1.png]


[Thumbnail for Tree2.png]

Joe Ess
Bartender

Joined: Oct 29, 2001
Posts: 8927
    
    9

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

Joined: Jul 24, 2013
Posts: 35
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.





 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
 
subject: Convert nested Java Object to tree structure