node selected in n-level tree

classic Classic list List threaded Threaded
7 messages Options
Reply | Threaded
Open this post in threaded view
|

node selected in n-level tree

Edwin Mercado
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

Reply | Threaded
Open this post in threaded view
|

Re: node selected in n-level tree

schof-2
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 <[hidden email]> 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
>
>
Reply | Threaded
Open this post in threaded view
|

RE: node selected in n-level tree

Edwin Mercado
In reply to this post by Edwin Mercado
ok, thanks!

-----Original Message-----
From: Sean Schofield [mailto:[hidden email]]
Sent: Tuesday, August 02, 2005 3:02 PM
To: MyFaces Discussion
Subject: Re: node selected in n-level tree


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 <[hidden email]> 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
>
>
Reply | Threaded
Open this post in threaded view
|

RE: node selected in n-level tree

CONNER, BRENDAN (SBCSI)
In reply to this post by Edwin Mercado
The way we did it was as follows (where processAction is an
actionListener method):

        public void processAction(ActionEvent event) throws
AbortProcessingException {
                UIComponent component = (UIComponent) event.getSource();
                while (!(component != null && component instanceof
HtmlTree)) {
                        component = component.getParent();
                }
                if (component != null) {
                        HtmlTree tree = (HtmlTree) component;
                        TestNode node = (TestNode) tree.getNode();
                        ...
                }
                ...
        }

- Brendan

-----Original Message-----
From: Sean Schofield [mailto:[hidden email]]
Sent: Tuesday, August 02, 2005 2:02 PM
To: MyFaces Discussion
Subject: Re: node selected in n-level tree


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 <[hidden email]> 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
>
>
Reply | Threaded
Open this post in threaded view
|

RE: node selected in n-level tree

CONNER, BRENDAN (SBCSI)
In reply to this post by Edwin Mercado
Actually, looking at that while loop again, I guess we should have coded
it as:

while (!(component == null || component instanceof HtmlTree)) {
        ...
}

- Brendan

-----Original Message-----
From: CONNER, BRENDAN (SBCSI)
Sent: Tuesday, August 02, 2005 2:07 PM
To: 'MyFaces Discussion'; 'Sean Schofield'
Subject: RE: node selected in n-level tree


The way we did it was as follows (where processAction is an
actionListener method):

        public void processAction(ActionEvent event) throws
AbortProcessingException {
                UIComponent component = (UIComponent) event.getSource();
                while (!(component != null && component instanceof
HtmlTree)) {
                        component = component.getParent();
                }
                if (component != null) {
                        HtmlTree tree = (HtmlTree) component;
                        TestNode node = (TestNode) tree.getNode();
                        ...
                }
                ...
        }

- Brendan

-----Original Message-----
From: Sean Schofield [mailto:[hidden email]]
Sent: Tuesday, August 02, 2005 2:02 PM
To: MyFaces Discussion
Subject: Re: node selected in n-level tree


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 <[hidden email]> 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
>
>
Reply | Threaded
Open this post in threaded view
|

RE: node selected in n-level tree

Edwin Mercado
In reply to this post by Edwin Mercado
thanks Brendan.

-----Original Message-----
From: CONNER, BRENDAN (SBCSI) [mailto:[hidden email]]
Sent: Tuesday, August 02, 2005 3:13 PM
To: MyFaces Discussion; Sean Schofield
Subject: RE: node selected in n-level tree


Actually, looking at that while loop again, I guess we should have coded
it as:

while (!(component == null || component instanceof HtmlTree)) {
        ...
}

- Brendan

-----Original Message-----
From: CONNER, BRENDAN (SBCSI)
Sent: Tuesday, August 02, 2005 2:07 PM
To: 'MyFaces Discussion'; 'Sean Schofield'
Subject: RE: node selected in n-level tree


The way we did it was as follows (where processAction is an
actionListener method):

        public void processAction(ActionEvent event) throws
AbortProcessingException {
                UIComponent component = (UIComponent) event.getSource();
                while (!(component != null && component instanceof
HtmlTree)) {
                        component = component.getParent();
                }
                if (component != null) {
                        HtmlTree tree = (HtmlTree) component;
                        TestNode node = (TestNode) tree.getNode();
                        ...
                }
                ...
        }

- Brendan

-----Original Message-----
From: Sean Schofield [mailto:[hidden email]]
Sent: Tuesday, August 02, 2005 2:02 PM
To: MyFaces Discussion
Subject: Re: node selected in n-level tree


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 <[hidden email]> 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
>
>
Reply | Threaded
Open this post in threaded view
|

Re: node selected in n-level tree

schof-2
Are lots of people using multiple level trees?  If so, maybe we should
update the simple examples with one using Brendan's approach.

sean

On 8/2/05, Edwin Mercado <[hidden email]> wrote:

> thanks Brendan.
>
> -----Original Message-----
> From: CONNER, BRENDAN (SBCSI) [mailto:[hidden email]]
> Sent: Tuesday, August 02, 2005 3:13 PM
> To: MyFaces Discussion; Sean Schofield
> Subject: RE: node selected in n-level tree
>
>
> Actually, looking at that while loop again, I guess we should have coded
> it as:
>
> while (!(component == null || component instanceof HtmlTree)) {
>         ...
> }
>
> - Brendan
>
> -----Original Message-----
> From: CONNER, BRENDAN (SBCSI)
> Sent: Tuesday, August 02, 2005 2:07 PM
> To: 'MyFaces Discussion'; 'Sean Schofield'
> Subject: RE: node selected in n-level tree
>
>
> The way we did it was as follows (where processAction is an
> actionListener method):
>
>         public void processAction(ActionEvent event) throws
> AbortProcessingException {
>                 UIComponent component = (UIComponent) event.getSource();
>                 while (!(component != null && component instanceof
> HtmlTree)) {
>                         component = component.getParent();
>                 }
>                 if (component != null) {
>                         HtmlTree tree = (HtmlTree) component;
>                         TestNode node = (TestNode) tree.getNode();
>                         ...
>                 }
>                 ...
>         }
>
> - Brendan
>
> -----Original Message-----
> From: Sean Schofield [mailto:[hidden email]]
> Sent: Tuesday, August 02, 2005 2:02 PM
> To: MyFaces Discussion
> Subject: Re: node selected in n-level tree
>
>
> 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 <[hidden email]> 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
> >
> >
>