12 Replies Latest reply on Apr 11, 2007 9:44 AM by trouby

    Tree with DnD support

    trouby

      Hi,

      I have a tree which looks like:

      <rich:tree switchType="ajax" style="width:180px" value="#{rolesFoldersTree.data}" var="item" nodeFace="#{item.type}" dragIndicator=":indicator">
       ..
       <rich:treeNode type="role" dragType="role" dragValue="#{item}">
       <h:outputText value="#{item.name}" />
       </rich:treeNode>
      </rich:tree>
      


      And a dropSupport tag as follows:
      <rich:dropSupport id="dndTest" acceptedTypes="role" dropValue="Role!" dropListener="#{um.flagedByDragAndDrop}">
      </rich:dropSupport>
      


      And the dropListener method which looks like:
      public void flagedByDragAndDrop(DropEvent event) {
       System.out.println("---------" + event.getDragValue() + "---------");
      }
      


      As it seems,after dragging, 'event.getDragValue()' always returns null,

      Shouldn't the drag value has to be equal to the 'dragValue' parameter in the 'treeNode' tag?


      As always, many thanks,

      Asaf.

        • 1. Re: Tree with DnD support
          trouby

          This was my mistake as I had the tree / dropSupport in different forms,


          Yet still, I see weird different values set in 'event.getDragValue()', I can't figure out how to control its values,

          Setting the 'dragValue' parameter in the treeNode tag does not affect its value at all,


          Thanks.

          • 2. Re: Tree with DnD support
            nbelaevski

            Hello!

            getDragValue() method return data object for the TreeNode being dragged. It shouldn't be allowed to be set at JSP page. I've filed issue in JIRA on that: http://jira.jboss.com/jira/browse/RF-77

            • 3. Re: Tree with DnD support
              trouby

              Hey,

              Alright regarding the TLD,

              getDragValue() method returns 'org.richfaces.component.ListRowKey' object type, with a value of 'x:y' where x=the ID of the parent of the selected treeNode and y=the ID of the selected treeNode,


              That doesnt look like the treeNode object of the selected node,

              Is that the normal behaviour?


              Asaf.

              • 4. Re: Tree with DnD support
                nbelaevski

                Hello!

                Please excuse me for pointing wrong. Legal drag/drop values should be of TreeRowKey type to allow developer to obtain either node data or node references. I've changed code in trunk to comply.

                Here is the code snippet to obtain data:

                ...
                Object rowKey = tree.getRowKey();
                try {
                 tree.setRowKey(event.getDragValue());
                
                 Object data = tree.getRowData();
                 TreeNode node = tree.getTreeNode();
                
                 ... //use it
                
                } finally {
                 tree.setRowKey(rowKey);
                }


                Note that there were no getTreeNode() method accessible in 3.0.0 release. It is accessible at trunk versions.

                • 5. Re: Tree with DnD support
                  trouby

                  That makes more sense,

                  How do I download the version from SVN?

                  Is there any auto archive and away to download a binary version from trunk? or any instructions on how to download the sources / compile&pack them?


                  thanks.

                  • 6. Re: Tree with DnD support
                    • 7. Re: Tree with DnD support
                      nbelaevski

                      Hello!

                      I've added a couple of shortcut methods to UITree class to get row data and tree node by key:

                      UITree#getRowData(Object)
                      and
                      UITree#getTreeNode(Object)

                      You need to just pass row key as argument and get back data or node

                      • 8. Re: Tree with DnD support
                        trouby

                        Hey,

                        Are there any samples? better documentation? probably I'm missing something...

                        I followed your directions, I always get 'null's all way long,
                        All samples shows TreeNodes that implements the 'TreeNode' interface and thats it.


                        Then I browsed the code, and extended by TreeNodes by the 'TreeDataNode' class.

                        Anyway, my 'rootTreeNode.setRowKey(event.getDragValue());' / getRowData returns null.

                        Probably I'm missing something, so a sample / more documentation would be good...

                        Thanks,

                        Asaf.

                        • 9. Re: Tree with DnD support
                          nbelaevski

                          getRowData() methods invokes getData() method of the TreeNode interface. Does it return something in your implementation?

                          • 10. Re: Tree with DnD support
                            trouby

                            In my implementation, as in samples, I return the treeNode itself in each of my TreeNodes,

                            And of course when the tree gets builds it invokes getData(),


                            But 'getRowData()' returns null.

                            If the state of the tree is important, I keep the tree in the session, and invoke getRowData() over the root treeNode,

                            Is that the correct way?

                            Asaf.


                            • 11. Re: Tree with DnD support
                              nbelaevski

                              I've added diagnostic output to our tree-demo sample. You can see how it's built... The code resides here:http://anonsvn.jboss.org/repos/richfaces/trunk/richfaces-samples/tree-demo/

                              • 12. Re: Tree with DnD support
                                trouby

                                Hey,

                                Yeah, works perfectly, including the new features of UITree,


                                BTW, at the moment I upgraded to the latest richfaces snapshot Tree's AJAX switchType stopped working (server/client works ok)

                                I also tried to upgrade to the newest Ajax4JSF, but it still does not work,



                                Thanks,

                                Asaf.