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 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 am currently having some trouble using my client side validation. I am using
I'm having some trouble with a script confirmation. By standard it's set to hide
I'm having some trouble with editing a gridview row's background color when Editing it.
I'm having some trouble mapping a byte array to a MySQL database in Hibernate
I'm having some trouble with Instruments. My app is working perfectly without crashes, but
I'm having some trouble with changing the value of a class at runtime and
I am having some trouble getting the graph created with jqplot to print with
I'm having some trouble figuring out how to 1) traverse a directory and 2)
I'm having some trouble understanding how to deal with ambiguity of constructors in D.
I'm having some trouble sending along more than one variable to the view. my

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.