4 Replies Latest reply on May 2, 2013 8:25 AM by agallo73

    dropListener not executed when dragging Node in rich:tree

    hombre2k

      Hello,

       

      I plan to migrate my Seam 2.2 application to Seam 3.1 and Richfaces 4. While testing the drag and drop functionality in rich:tree i noticed the following problem:

       

      I tried to implement the rich:tree example from the Richfaces 4.1 Component Reference Guide in combination with the Drag and Drop example from the Richfaces 4.2.0.CR1 showcase. In addition to the tree i added two rich:panels with Drag and Drop funtionality to check, whether drag and drop works outside of the tree. The DragIndicator works fine and indicates when the dragged element is placed over an appropriate dropTarget. When i drag from one of the panels and drop on the other panel or a treeNode everything works fine. But when i try to drag a treeNode to one of the two panels or another treeNode the dropListener is not executed. The DragIndicator works correct.

      An other problem is, that event.getDragValue() and event.getDropValue() returns null.

      Any suggestions?

       

      Here is the code:

       

      {code:xml}

      <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

      <html xmlns="http://www.w3.org/1999/xhtml"

            xmlns:ui="http://java.sun.com/jsf/facelets"

            xmlns:h="http://java.sun.com/jsf/html"

            xmlns:f="http://java.sun.com/jsf/core"

            xmlns:a4j="http://richfaces.org/a4j"

            xmlns:rich="http://richfaces.org/rich">

      <f:view>

        <h:head>

        </h:head>

        <h:body>

          <h:outputStylesheet>

              .panelc { width:25%; }

              .valign { vertical-align:top; }

              .dropTargetPanel { width: 90%; }

              .footerClass {

              text-align: center;

              padding-top: 5px;

              }

       

              .default{

              font-size:11px;

              cursor:pointer;

              width:100px;

              border:1px solid gray;

              padding:2px

              }

              .rf-ind-drag.default{

              padding-left:30px;

              background-image: url("#{facesContext.externalContext.requestContextPath}/images/dnd/default.gif");

              background-position: 5px;

              background-repeat: no-repeat;

              }

              .rf-ind-drag.accept{

              background-image: url("#{facesContext.externalContext.requestContextPath}/images/dnd/accept.gif");

              background-position: 5px;

              background-repeat: no-repeat;

              border:2px solid green

              }

              .rf-ind-drag.reject{

              border:2px solid red;

              background-image: url("#{facesContext.externalContext.requestContextPath}/images/dnd/reject.gif");

              background-position: 5px;

              background-repeat: no-repeat;

              }

          </h:outputStylesheet>

          <rich:dragIndicator id="ind" acceptClass="accept" rejectClass="reject" draggingClass="default"><h:outputText value="drag me!" /></rich:dragIndicator>

          <h:form>

            <a4j:outputPanel ajaxRendered="false" layout="block">

              <rich:tree value="#{treeBean.rootNodes}" var="station" id="tree" toggleType="client" selectionType="ajax">

                <rich:treeNode id="treenode">

                  <a4j:outputPanel id="node">

                    <h:outputText value="#{station.data}" />

                    <rich:dragSource value="#{station.data}" type="dnd" dragIndicator="ind"/>

                    <rich:dropTarget  value="#{station.data}" acceptedTypes="dnd" dropListener="#{treeBean.processDrop}"/>

                  </a4j:outputPanel>

                </rich:treeNode>

              </rich:tree>

            </a4j:outputPanel>

            <rich:panel id="dndpanel1">

              <rich:dragSource dragIndicator="ind" value="dragPanel1" type="dnd"/>

              <rich:dropTarget value="dropPanel1" acceptedTypes="dnd" dropListener="#{treeBean.processDrop}"/>

            </rich:panel>

            <rich:panel id="dndpanel2">

              <rich:dragSource dragIndicator="ind" value="dragPanel2" type="dnd"/>

              <rich:dropTarget value="dropPanel2" acceptedTypes="dnd" dropListener="#{treeBean.processDrop}"/>

            </rich:panel>

          </h:form>  

       

          <rich:messages/>

        </h:body>

      </f:view>

      </html>

      {code}

       

      {code}

      package tree;

      import org.richfaces.model.TreeNodeImpl;

       

      public class DataHolderTreeNodeImpl extends TreeNodeImpl {

       

          private Object data;

       

          public DataHolderTreeNodeImpl() {

              super();

          }

       

          public DataHolderTreeNodeImpl(boolean leaf, Object data) {

              super(leaf);

              this.data = data;

          }

       

          public Object getData() {

              return data;

          }

       

       

          @Override

          public String toString() {

              return super.toString() + " >> " + data;

          }

      }

      {code}

       

      {code}

      package tree;

       

      import javax.enterprise.context.SessionScoped;

      import javax.inject.Inject;

      import javax.inject.Named;

       

      import org.jboss.seam.international.status.Messages;

      import org.jboss.solder.logging.Logger;

      import org.richfaces.event.DropEvent;

       

      import java.io.Serializable;

       

      @Named

      @SessionScoped

      public class TreeBean implements Serializable {

       

          /**

           *

           */

          private static final long serialVersionUID = 1L;

       

          private DataHolderTreeNodeImpl stationRoot;

       

          private DataHolderTreeNodeImpl rootNodes;

       

          @Inject

          private Messages messages;

       

          @Inject

          private Logger log;

       

          public DataHolderTreeNodeImpl getRootNodes() {

              if (rootNodes == null) {

                  String[] kickRadioFeed = {"Hall & Oates - Kiss On My List",

                          "David Bowie - Let's Dance",

                          "Lyn Collins - Think (About It)",

                          "Kim Carnes - Bette Davis Eyes",

                          "KC & the Sunshine Band - Give It Up"};

                  stationRoot = new DataHolderTreeNodeImpl(false, "KickRadio");

                  for (int i = 0; i<kickRadioFeed.length; i++) {

                      DataHolderTreeNodeImpl child = new DataHolderTreeNodeImpl(true, kickRadioFeed[i]);

                      stationRoot.addChild(i, child);

                  }

                  rootNodes = new DataHolderTreeNodeImpl();

                  rootNodes.addChild(0, stationRoot);

              }

              return rootNodes;

          }

       

          public void processDrop(DropEvent event) {

              String dragValue = (String) event.getDragValue();

              String dropValue = (String) event.getDropValue();

              messages.info("{0} dropped on {1}", dragValue, dropValue);

              log.infof("%s dropped on %s", dragValue, dropValue);

          }

      }

      {code}

       

       

      Greetings,

      Jan