4 Replies Latest reply on Feb 14, 2008 10:00 AM by Fab Mars

    Rich:tree and drag and drop how-to

    Fab Mars Novice

      I had to develop a drag'n'drop tree with folders and documents like you can find in Thunderbird for example.
      The builtin drag'n'drop feature of the rich:tree is truly excellent, and the developer's guide explains a lot.

      However I could never know how to make it to work properly, that is set the good events to know what's dragged and where it's dropped. It's written nowhere. At first I thought the tree would reorder the nodes by itself, but it wasn't the case. So I tried progrmatically. Curiously, setting a dragListener and a dropListener is not the solution, as the dragListener may be called AFTER the dropListener (on my 3.1.4GA it happens once in a while anyway).

      By digging on these forums I found some post of Alex Belov that put me on the good path. My solution was to use a nodeSelectionListener and a dropListener on the tree. Basically my backingbean is kept alive and the 2 listeners are like this :

       private TreeNode selectedNode;
       public void onSelectNode(NodeSelectedEvent e) {
       HtmlTree tree = (HtmlTree)e.getSource();
       selectedNode = tree.getTreeNode();
       public void processDrop(DropEvent e) {
       HtmlTreeNode dropSource = (HtmlTreeNode)e.getSource();
       HtmlTree tree = (HtmlTree)dropSource.getParent();
       TreeNode dropNode = tree.getTreeNode();
       dropNode.addChild(selectedNode.getData(), selectedNode);

      Now, I'm not even sure I'm doing it the proper way. I think drag'n'drop in trees should be explained better in the developer's guide. Could you guys just add some paragraph about it ? Thanks.