1 Reply Latest reply on Dec 1, 2008 9:37 AM by nbelaevski

    Retrieving TreeNode from recursiveTreeNodesAdaptor

    rcurth

      Hi everybody,
      I'm stucked with this problem:

      I'm trying to implement a Drag'n Drop Tree where I can move the nodes around. The recursiveTreeNodesAdaptor seems to be perfect to fullfill my requirements.

      <rich:tree switchType="ajax" nodeSelectListener="#{depotManager.processSelection}" ajaxSubmitSelection="true"
      reRender="depotTab" id="tree" dragIndicator="dragIndicator" dropListener="#{depotManager.dropListener}" >
       <rich:recursiveTreeNodesAdaptor roots="#{depotManager.getRoot()}" var="item" nodes="#{item.children}">
       <rich:treeNode acceptedTypes="depot" ragType="depot">
       <rich:dndParam name="label" type="drag">
       #{item.name}
       </rich:dndParam>
       <h:outputText value="#{item.name}" />
       </rich:treeNode>
       </rich:recursiveTreeNodesAdaptor>
      </rich:tree>



      The problem occurs while implementing the dropListener method. I had a look at the SimpleTreeDndBean class, which is used by the drag'n drop sample at RichFaces LiveDemo. Okay, so far so good.

      While retrieving the draggedNode I always get a null return value, although the dragNodeKey is not null.

      TreeRowKey dragNodeKey = (dropEvent.getDragValue() instanceof TreeRowKey) ? (TreeRowKey) dropEvent.getDragValue() : null;
      TreeNode draggedNode = dragNodeKey != null ? srcTree.getTreeNode(dragNodeKey) : null;


      A fast look at the API tells me:
      Adaptor-based trees do not use TreeNode, so the method always return null for such trees. Please use UIDataAdaptor.getRowData() instead.


      The data I will recieve with this is, btw, not a TreeNode. Okay, here it comes. How am I supposed to do this:

      TreeNode parentNode = draggedNode.getParent();
      state = srcTree.removeNode(dragNodeKey);
      Object rowKey = srcTree.getTreeNodeRowKey(parentNode);


      if draggedNode is always null, an Adaptor-based tree even not use TreeNodes.

      I would be pleased, if anyone can help me out with this problem.
      Thanks in advance

      Rene