Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8480345
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 10, 20262026-06-10T19:16:12+00:00 2026-06-10T19:16:12+00:00

Primefaces TreeTable nodes seems to work in a reverse way. You create a parent,

  • 0

Primefaces TreeTable nodes seems to work in a reverse way.

You create a parent, then you create a child, than you tell the child what parent it belongs to. The parents should know their children, not the other way.

So… my problem is:

I need to load an undefined ammount of data from my database(grandparents, parents, children and grand children).

How to dinamically load them into the TreeTable? I can’t think of a way inside my for-each to create TreeNodes and set it`s parents.

Anyone can give me and idea?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-10T19:16:13+00:00Added an answer on June 10, 2026 at 7:16 pm

    I haven’t tested out this solution yet, but I think it should work. the examples on the primefaces showcase are all hard coded. To make it dynamic, You’ll have to work with Arrays.

    So for example the section of hardcoded code below:

     TreeNode documents = new DefaultTreeNode(new Document("Documents", "-", "Folder"), root);  
     TreeNode pictures = new DefaultTreeNode(new Document("Pictures", "-", "Folder"), root);  
     TreeNode music = new DefaultTreeNode(new Document("Music", "-", "Folder"), root);
    

    Can be replaced with:

     Map<String, TreeNode> rootNodes = new HashMap<String, TreeNode>();
    
     //Retrieve the list of root Nodes. eg Tables in the database.
     for(Table table : databaseTables){
    
        //table.getTableName() will be the name of the node, it could be something like "music" or "documents"
        rootNodes.add(table.getTableName(), new DefaultTreeNode(table.getTableName(), new Document......, root);
     }
    

    The reason I add them to the map is so that if you want to refer to them, you can use the key as a reference.
    now If you want to add nodes to the pictures node for example

     //Create a new map
     Map<String, TreeNode> pictureNodes = new HashMap<String, TreeNode>();
    
     //now loop through your picture objects
    for(picture : pictures){
        pictureNode.add(new DefaultTreeNode(picture.getName(), ......., root.get("pictures"));
    }
    

    Using this method, you can recursively loop through as many hierarchies as possible. I haven’t been able to test this code (just notepad++) because I’m currently at the office. but try it out, if you’re still stuck I can do something more detailed when I get home in a few hours.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Is it possible to use primefaces datalist and fieldset elements in a nested way.
I am using primefaces-3.0.M3 with Tomcat 7. Spinner always shows blank rather than the
I cant even get to work the PrimeFaces showcase code at all. What is
I am new with Primefaces and I try to use a treeTable from Primefaces
I am working with primefaces. I need to write a java script function that
I am using Primefaces and JSF2 . All my .xhtml files are dumped in
I'm using primefaces' accordion panel. Inside the tabs i have forms which are created
i am using primefaces library this is my jsp page source: <%@taglib uri=http://primefaces.prime.com.tr/ui prefix=p%>
This is from the Primefaces docs: Button Icons An icon on a button is
My product is using JSF with Primefaces 2.2. What I need is to process

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.