You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@myfaces.apache.org by Sean Schofield <se...@gmail.com> on 2006/05/30 02:31:32 UTC

[tree2] Re: Get selected node with getNode()

Store a reference to your tree in your backing bean with:

<t:tree2 id="foo" ... binding="#{treeBacker.tree}">

Then in your action method you have

public String selectedNode()
{
     this.selectedNode = tree.getNode();
     return("main");
}

The tree always knows the current node when processing an event (much
like a data table knows the current row.)

Sean

On 5/27/06, Daniel Haensse <ha...@swissembedded.com> wrote:
> Dear list,
>
> with tomahawk 1.1.2 in tree2 the getNode() member function is no longer
> implemented in the class TreeModelBase.
>
> Is their a work around, I would like to get the user selected item of the
> tree, currently I placed a
> action="#{mainScreenView.selectedNode}" as commandLink on each item.
>
> Then I catch the action with
>
>  public String selectedNode() {
>    this.selectedNode = this._treeModel.getNode();
>    return("main");
>   }
>
> Any hints? Why was this removed?
>
> best regards
>
> Dani
>

Re: [tree2] Re: Get selected node with getNode()

Posted by Daniel Haensse <ha...@swissembedded.com>.
class HtmlTree was the missing link, your getNode() is referencing on that.

Thanks for your hints.

Dani

JSF code:
    <t:tree2 id="serverTree" value="#{mainScreenView.treeData}" var="node" 
varNodeToggler="t" clientSideToggle="false" binding="#{mainScreenView.tree}">
...

Java code (modified from old code):
public class MainScreenView {
	private TreeModelBase _treeModel = null;
	private TreeNode selectedNode;
	private HtmlTree htmltree = new HtmlTree();
...
      public TreeModel getTreeData() {
                // Create tree if TreeModel is null
                if (_treeModel == null) {
                        ... create tree
                }
                return _treeModel;
        }

	public void setTree(HtmlTree tree)
    {
        this.htmltree = tree;
    }

    public HtmlTree getTree()
    {
        return this.htmltree;
    }
    
	public String selectedNode() {
		this.selectedNode = this.htmltree.getNode();
		return ("main");
	}
...

Am Donnerstag, 1. Juni 2006 13.59 schrieb Sean Schofield:
> I understand that its no longer there.  I was trying to give you an
> alternate way to do what you want.  getNode() is not coming back so
> you will need to adapt.
>
> Reread my last answer again.  Basically you use the binding attribute
> of tree2 to bind a reference to the tree to your backing bean.  (The
> binding attribute is common to most components and this strategy is
> described in lots of JSF books.)  Once you have a reference to the
> tree in your backing bean, your selectedNode() method can just ask the
> tree what the current node is.
>
> Sean
>
> On 5/30/06, Daniel Haensse <ha...@swissembedded.com> wrote:
> > Hi Sean,
> >
> > thanks for the quick reply. I don't understand your answer :-(
> >
> > My problem is that getNode() does not exist anymore in class
> > TreeModelBase.
> >
> > Eclipse claims that "The method getNode() is undefined for the type
> > TreeModelBase" in the line
> > this.selectedNode = this._treeModel.getNode(); (see class abstract below)
> >
> > Before the update of the tomahawk library everything worked fine :-(
> >
> > When I dig in the source code repository of the tree2 implementation, I
> > can see that TreeModelBase has no getNode() function.
> >
> > old code worked fine before update:
> >
> > public class MainScreenView {
> >         private TreeModelBase _treeModel = null;
> >
> >         private TreeNode selectedNode;
> >
> >         public TreeModel getTreeData() {
> >                 // Create tree if TreeModel is null
> >                 if (_treeModel == null) {
> >                         ... create tree
> >                 }
> >                 return _treeModel;
> >         }
> >
> >         public String selectedNode() {
> >                 this.selectedNode = this._treeModel.getNode();
> >                 return ("main");
> >         }
> > }
> >
> >     <t:tree2 id="serverTree" value="#{mainScreenView.treeData}"
> > var="node" varNodeToggler="t" clientSideToggle="false">
> >         <f:facet name="location-folder">
> >             <h:panelGroup>
> >              <h:commandLink immediate="true"
> > actionListener="#{t.setNodeSelected}"
> > action="#{mainScreenView.selectedNode}">
> >             ... rendered elements removed
> >              </h:commandLink>
> >             </h:panelGroup>
> >         </f:facet>
> >
> > regards
> >
> > Dani


Re: [tree2] Re: Get selected node with getNode()

Posted by Sean Schofield <se...@gmail.com>.
I understand that its no longer there.  I was trying to give you an
alternate way to do what you want.  getNode() is not coming back so
you will need to adapt.

Reread my last answer again.  Basically you use the binding attribute
of tree2 to bind a reference to the tree to your backing bean.  (The
binding attribute is common to most components and this strategy is
described in lots of JSF books.)  Once you have a reference to the
tree in your backing bean, your selectedNode() method can just ask the
tree what the current node is.

Sean

On 5/30/06, Daniel Haensse <ha...@swissembedded.com> wrote:
> Hi Sean,
>
> thanks for the quick reply. I don't understand your answer :-(
>
> My problem is that getNode() does not exist anymore in class TreeModelBase.
>
> Eclipse claims that "The method getNode() is undefined for the type
> TreeModelBase" in the line
> this.selectedNode = this._treeModel.getNode(); (see class abstract below)
>
> Before the update of the tomahawk library everything worked fine :-(
>
> When I dig in the source code repository of the tree2 implementation, I can
> see that TreeModelBase has no getNode() function.
>
> old code worked fine before update:
>
> public class MainScreenView {
>         private TreeModelBase _treeModel = null;
>
>         private TreeNode selectedNode;
>
>         public TreeModel getTreeData() {
>                 // Create tree if TreeModel is null
>                 if (_treeModel == null) {
>                         ... create tree
>                 }
>                 return _treeModel;
>         }
>
>         public String selectedNode() {
>                 this.selectedNode = this._treeModel.getNode();
>                 return ("main");
>         }
> }
>
>     <t:tree2 id="serverTree" value="#{mainScreenView.treeData}" var="node"
> varNodeToggler="t" clientSideToggle="false">
>         <f:facet name="location-folder">
>             <h:panelGroup>
>              <h:commandLink immediate="true"
> actionListener="#{t.setNodeSelected}"
> action="#{mainScreenView.selectedNode}">
>             ... rendered elements removed
>              </h:commandLink>
>             </h:panelGroup>
>         </f:facet>
>
> regards
>
> Dani
>
>

Re: [tree2] Re: Get selected node with getNode()

Posted by Daniel Haensse <ha...@swissembedded.com>.
Hi Sean,

thanks for the quick reply. I don't understand your answer :-(

My problem is that getNode() does not exist anymore in class TreeModelBase.

Eclipse claims that "The method getNode() is undefined for the type 
TreeModelBase" in the line
this.selectedNode = this._treeModel.getNode(); (see class abstract below)

Before the update of the tomahawk library everything worked fine :-(

When I dig in the source code repository of the tree2 implementation, I can 
see that TreeModelBase has no getNode() function.

old code worked fine before update:

public class MainScreenView {
	private TreeModelBase _treeModel = null;

	private TreeNode selectedNode;

	public TreeModel getTreeData() {
		// Create tree if TreeModel is null
		if (_treeModel == null) {
			... create tree
		}
		return _treeModel;
	}

	public String selectedNode() {
		this.selectedNode = this._treeModel.getNode();
		return ("main");
	}
}

    <t:tree2 id="serverTree" value="#{mainScreenView.treeData}" var="node" 
varNodeToggler="t" clientSideToggle="false">
        <f:facet name="location-folder">
            <h:panelGroup>
             <h:commandLink immediate="true" 
actionListener="#{t.setNodeSelected}" 
action="#{mainScreenView.selectedNode}">
            ... rendered elements removed
             </h:commandLink>
            </h:panelGroup>
        </f:facet>

regards

Dani