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?
Populating Tree from Database
-
- Prime
- Posts: 18616
- Joined: 05 Jan 2009, 00:21
- Location: Cybertron
- Contact:
TreeNode has a data you can use to hold custom data like id, no?
-
- Prime
- Posts: 18616
- Joined: 05 Jan 2009, 00:21
- Location: Cybertron
- Contact:
Ok
Ok, just a quick question
In my
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?
In my
Code: Select all
public void onNodeSelect(NodeSelectEvent event) {
selectedNode = event.getTreeNode(); }
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?
-
- Prime
- Posts: 18616
- Joined: 05 Jan 2009, 00:21
- Location: Cybertron
- Contact:
Code: Select all
((YourObject) event.getTreeNode().getData()).getId()
-
- Information
-
Who is online
Users browsing this forum: No registered users and 65 guests