In database table, i have maintained parent and child folder relationship as shown below datatable. Using that relationship i need to create hierarchical structure in a jsp web page. To display that structure i used http://myfaces.apache.org/tomahawk t:tree2 component.My requirement is, I need to fetch data from database and store that relationship in java variable. To do that i need a recursive technique to store tree structure or(hierarchical structure) in java variable. Please help to find answer.
DataTable:
hierarchical View of Directory structure:
Thank you
You can use recursion to iterate over it.
void processChilds(Item child) {
List<Item> childs = selectChilds(child);
for(Item i: childs) {
//do smth
processChilds(i);
}
}
Or you need to select all records at once and then parse it into your own structure of objects. It can be HashMap or your own tree-like structure.
class Item {
List<Item> childs;
}
I suggest you go with the first one (because it's simple to code) unless your tree is really deep
Collected from the Internet
Please contact [email protected] to delete if infringement.
Comments