<t:tree2 var="n" value="#{bean.treeModel}">
<f:facet name="node">
<t:commandLink actionListener="#{bean.nodeClicked}"
value="#{n.description}">
<t:updateActionListener property="#{bean.clickedNode}"
value="#{n}" />
</t:commandLink>
</f:facet>
</t:tree2>
@Name("bean")
public class Bean {
private TreeModel treeModel;
private TreeNode clickedNode;
public TreeModel getTreeModel() { return this.treeModel; }
public void setTreeModel(TreeModel treeModel) { this.treeModel = treeModel; }
public TreeNode getClickedNode() { return this.clickedNode; }
public void setClickedNode(TreeNode clickedNode) { this.clickedNode
= clickedNode; }
public void nodeClicked(ActionEvent evt) {
// open JDBC connection and do whatever you want to "this.clickedNode"
}
}
If you want to store custom properties on the node, just implement
TreeNode or extend TreeNodeBase and put whatever you want on it.
-A
On 1/15/07, Wiebke Henrici <[EMAIL PROTECTED]> wrote:
Hi,
I am new to programming with MyFaces and I have some questions
concerning the tree2 component.
I have managed to get the example running and now I want to change it a
bit. When a user clicks on a leaf (maybe it has to be a command link for
that), a query to the database has to be made. Do I have to work with
some kind of action listener there?
For the database query, I need some extra information from the leaf
clicked. Can I store this extra information (the ID of the database
entry) in the leaf when I fill the tree data with data from the
database? You know, as hidden information, like I display the name of
the leaf, but save the ID I also got from the database together with the
leaf so I can read it when the user clicks a leaf.
I hope someone has some lines of code for me which shows how to use the
event that the command link was clicked and how to store this extra
hidden information.
Thanks for your help!!
Wiebke