Populating Tree from Database

UI Components for JSF
Post Reply
grizli
Posts: 82
Joined: 11 Nov 2009, 16:36

08 Mar 2010, 17:39

I'm trying to populate the Tree component from a Database, however, I ran into something I for see will be an issue. Unless I'm missing something :)
Once tree is populated, and items in it are selected, in my onSelected method I'll need to capture not just treenode name, but some sort of an ID. After all, nodes can have the same text, but IDs would be different.
So I created a public sub-class within my backing bean, with just 2 parameters (i.e. id, name)
and when I iterate through my ResultSet from DB, I add new tree nodes as such:
TreeNode somenode = new TreeNode(new TreeItem(rs.getString("id"), rs.getString("name")), root);

Is this not supported? If not - how do you uniquely identify nodes?

cagatay.civici
Prime
Posts: 18616
Joined: 05 Jan 2009, 00:21
Location: Cybertron
Contact:

08 Mar 2010, 17:41

TreeNode has a data you can use to hold custom data like id, no?

grizli
Posts: 82
Joined: 11 Nov 2009, 16:36

08 Mar 2010, 18:09

Don't ask..... :mrgreen:

cagatay.civici
Prime
Posts: 18616
Joined: 05 Jan 2009, 00:21
Location: Cybertron
Contact:

08 Mar 2010, 19:03

Ok :)

grizli
Posts: 82
Joined: 11 Nov 2009, 16:36

08 Mar 2010, 22:35

Ok, just a quick question :D
In my

Code: Select all

public void onNodeSelect(NodeSelectEvent event) {
        selectedNode = event.getTreeNode(); }
How do I get an "id" from getData()?

I have an object for each treenode that consists of 5 elements, one of them is "id". How do I pull an "id" from selectedNode?

cagatay.civici
Prime
Posts: 18616
Joined: 05 Jan 2009, 00:21
Location: Cybertron
Contact:

09 Mar 2010, 02:03

Code: Select all

((YourObject) event.getTreeNode().getData()).getId()
You can look at user's guide or javadocs for more information.

Post Reply

Return to “PrimeFaces”

  • Information
  • Who is online

    Users browsing this forum: No registered users and 65 guests