You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@myfaces.apache.org by Edwin Mercado <em...@cra.com> on 2005/08/02 19:48:00 UTC

node selected in n-level tree

Hi,
I'm using the tree2 component, and the tree can has n-levels
(child->parent->grandparent->...).
How can I detected the selected node without using the t.setNodeSelected?
The reason
I can't use the t.setNodeSelected is because I am using my own backing
method to do some other stuff
when a node has been clicked/selected. When I had a 2-level tree, I was able
to do something like this:

  UIComponent parent =
component.getParent().getParent().getParent().getParent();

  HtmlTree tree = (HtmlTree) parent;
  TreeNode node = tree.getNode();

but now with an n-level tree, it's a little bit different. Does anybody have
a clever way of figuring out the
selected node?
I think the following code might work but it doesn't seem
"performance-friendly":

UIComponent component;
while (component instanceof HtmlTree)
	component = component.getParent();

TreeNode node = tree.getNode();

(I haven't tried it out yet)
Edwin


Re: node selected in n-level tree

Posted by Sean Schofield <se...@gmail.com>.
Have you seen the recent discussion ("tree2 summit") on myfaces-dev
list?  We are considering moving this functionality to a new TreeModel
interface so the user could control node expansion.  The same could be
said for node selection.

sean

On 8/2/05, Edwin Mercado <em...@cra.com> wrote:
> Hi,
> I'm using the tree2 component, and the tree can has n-levels
> (child->parent->grandparent->...).
> How can I detected the selected node without using the t.setNodeSelected?
> The reason
> I can't use the t.setNodeSelected is because I am using my own backing
> method to do some other stuff
> when a node has been clicked/selected. When I had a 2-level tree, I was able
> to do something like this:
> 
>   UIComponent parent =
> component.getParent().getParent().getParent().getParent();
> 
>   HtmlTree tree = (HtmlTree) parent;
>   TreeNode node = tree.getNode();
> 
> but now with an n-level tree, it's a little bit different. Does anybody have
> a clever way of figuring out the
> selected node?
> I think the following code might work but it doesn't seem
> "performance-friendly":
> 
> UIComponent component;
> while (component instanceof HtmlTree)
>         component = component.getParent();
> 
> TreeNode node = tree.getNode();
> 
> (I haven't tried it out yet)
> Edwin
> 
>