3 Replies Latest reply on Aug 21, 2009 2:32 PM by nbelaevski

    Please... Need help on DragnDrop Tree...

      I have the following code almost the same as the demo website except I hoping to enable drag and drop to any folder and not only the
      top folders (under root):

      <rich:dragIndicator id="indicator1" >
       <f:facet name="single">
       <h:graphicImage styleClass="indicatorPicture" value="/richfaces/jQuery/images/{draggedImage}" />
       </f:facet>
       </rich:dragIndicator>
       <rich:dragIndicator id="indicator2" />
      
       <h:panelGrid columns="2" width="100%" columnClasses="col1,col2">
      
       <rich:tree ajaxKeys="#{null}" style="width:300px" nodeSelectListener="#{treeDndBean.processSelection}"
       reRender="#{areaToRerender}" ajaxSubmitSelection="true" switchType="client" dragIndicator="indicator2"
       value="#{treeDndBean.treeNode}" var="item" id="tree" treeNodeVar="treeNode"
       dropListener="#{treeDndBean.dropListener}" nodeFace="#{treeNode.leaf ? 'leaf' : 'node'}">
       <rich:treeNode type="node" acceptedTypes="pic">
       <h:outputText value="#{item}"/>
       </rich:treeNode>
       <rich:treeNode type="leaf" dragType="pic">
       <rich:dndParam name="label" type="drag">#{item}</rich:dndParam>
       <h:outputText value="#{item}"/>
       </rich:treeNode>
       </rich:tree>
      
       <a4j:commandButton value="New folder" action="#{treeDndBean.newFolder}" reRender="tree" />
       <a4j:commandButton value="New leaf" action="#{treeDndBean.newLeaf}" reRender="tree" />
      
       </h:panelGrid>
      


      Everything works fine except that the dropListener is never called eventhough it is allowed to drop (based on the drag indicator). I overwrote the isLeaf method of TreeNode in my implementation and I made sure, leaf is really a leaf (that is, it has no children). If I replace
      nodeFace="#{treeNode.leaf ? 'leaf' : 'node'}"
      

      with
      nodeFace="#{treeNode.parent == null ? 'node' : 'leaf'}"
      

      I can drop into top folders (same as the demo).

      Another thing I don't understand is that if I write something like nodeFace="#{treeNode.type == 'leaf' ? 'leaf' : 'node'}" when I select a node I have the following exception: Property 'type' not found on type org.richfaces.model.CacheableTreeNodeImpl
      No idea where does CacheableTreeNodeImpl come from and to be honest it is hard to understand how this works with the available documentation.

      I would really appreciate any help...

      Thanks in advance!

      Arnaud.

        • 1. Re: Please... Need help on DragnDrop Tree...
          nbelaevski

          Hello Arnaud,

          There's a request caching for model in the tree component and it's on by default, that's where these nodes are coming from. You can switch caching off by setting preserveModel="none" or try 3.3.1.GA if you're not using it - I've fixed similar issue there - maybe this will help?

          • 2. Re: Please... Need help on DragnDrop Tree...

            Hi,

            I've just try with preserveModel='none' and the nodeFace="#{treeNode.leaf ? 'leaf' : 'node'} works fine now.
            I'm not sure but it looks like if preserveModel='none' is not used the isLeaf method call is made on TreeNodeImpl instead of my implementation of TreeNodeImpl. And probably TreeNodeImpl for some reason does not return the expected value.
            When preserveModel='none' is used, I guess the call is made on my implementation and the expected value is returned.

            Anway, it works fine now and thank you for your time!

            Arnaud.

            • 3. Re: Please... Need help on DragnDrop Tree...
              nbelaevski

              Arnaud,

              You're right that's exactly how it works.