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

  • SEARCH
  • Home
  • 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 6145859
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T18:51:32+00:00 2026-05-23T18:51:32+00:00

I´m having some trouble implementing a dynamic tree structure using the primefaces tree implementation.

  • 0

I´m having some trouble implementing a dynamic tree structure using the primefaces tree implementation. In the showcase provided by primeface, the structure of the code is like below. This is however very static. I´m trying to figure out how I could do this with data fetched from a database, where the depth of the tree would be unknown at compile time.

I`m thinking that I probabply need some recursive method to implement this, but I cannot quite get my head around what the implementation would look like.

Any thoughts?

Below is the example code from primefaces

private TreeNode root;
private TreeNode selectedNode;

public TreeBean() {
    root = new DefaultTreeNode("Root", null);
    TreeNode node0 = new DefaultTreeNode("Node 0", root);
    TreeNode node1 = new DefaultTreeNode("Node 1", root);
    TreeNode node2 = new DefaultTreeNode("Node 2", root);

    TreeNode node00 = new DefaultTreeNode("Node 0.0", node0);
    TreeNode node01 = new DefaultTreeNode("Node 0.1", node0);

    TreeNode node10 = new DefaultTreeNode("Node 1.0", node1);
    TreeNode node11 = new DefaultTreeNode("Node 1.1", node1);

    TreeNode node000 = new DefaultTreeNode("Node 0.0.0", node00);
    TreeNode node001 = new DefaultTreeNode("Node 0.0.1", node00);
    TreeNode node010 = new DefaultTreeNode("Node 0.1.0", node01);

    TreeNode node100 = new DefaultTreeNode("Node 1.0.0", node10);
}
  • 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-05-23T18:51:33+00:00Added an answer on May 23, 2026 at 6:51 pm
    private TreeNode root;
    
    private TreeNode selectedNode;
    
    public TreeBean() {
    root = new DefaultTreeNode("Root", null);
    List rootNodes<Employee> = SearchDao.getRootNodes();
    
    Iterator it = rootNodes.iterator();
    while (it.hasNext()) {
    
    TreeNode node1 = new DefaultTreeNode(**it.next()**, root);
        **/* in place of it.next() I need to display empName. When I click on empName, I need to get the Id(Pkey). */**
    
    }
    
    }
    
    public TreeNode getRoot() {
    return root;
    }
    
    public TreeNode getSelectedNode() {
    return selectedNode;
    }
    
    public void setSelectedNode(TreeNode selectedNode) {
    this.selectedNode = selectedNode;
    }
    
    
    
    public void addChildNode(ActionEvent actionEvent) {
    System.out.println("Selected Node: "+getSelectedNode().toString());
    TreeNode newNode = new DefaultTreeNode("Node New", getSelectedNode());
    getSelectedNode().setExpanded(true);
    }
    public void addTopicBelow(ActionEvent actionEvent){
    TreeNode newNode = new DefaultTreeNode("Node New", getSelectedNode().getParent());
    }
    public void deleteNode(ActionEvent actionEvent){
     System.out.println("Node to be deleted: "+getSelectedNode().toString());
     //getSelectedNode().
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm having some trouble implementing pure virtual functions inherited from some abstract class, when
Related directly to this post , I am having trouble implementing some sound advice
I'm building a website using Zend Framework and having trouble implementing modules and custom
Having some trouble here with this. The setup: A select object with a choice
I received some helpful code here on StackOverflow to load the last used document
I'm having trouble getting MPI_Gatherv to work with a std::vector. I have written a
For a CS class I need to solve an assigned problem using three data
I am making use of jQuery's .autocomplete plugin, and I would appreciate some assistance
I've been learning OpenGL for the past couple of weeks and I've run into
This is a total beginner question, I've spent the past hour searching both stackoverflow

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.