4 Replies Latest reply on Jan 6, 2009 10:26 AM by Lindalva Santos

    Drag and Drop problem

    marek kocjev Newbie

      Hello all together,

      im trying to get the 'Drag and Drop' example running from the demo-site.
      When i start my page, all is loaded but i cant drag.

      The dragindicator does not start, nothing happens.
      Here is my code.

      DndBean.java

      import java.util.ArrayList;
      
      public class DndBean {
       private ArrayList<Framework> containerPHP;
       private ArrayList<Framework> containerCF;
       private ArrayList<Framework> containerDNET;
       private ArrayList<Framework> frameworks;
      
       public ArrayList<Framework> getContainerCF() {
       return containerCF;
       }
      
       public void setContainerCF(ArrayList<Framework> containerCF) {
       this.containerCF = containerCF;
       }
      
       public ArrayList<Framework> getContainerDNET() {
       return containerDNET;
       }
      
       public void setContainerDNET(ArrayList<Framework> containerDNET) {
       this.containerDNET = containerDNET;
       }
      
       public ArrayList<Framework> getContainerPHP() {
       return containerPHP;
       }
      
       public void setContainerPHP(ArrayList<Framework> containerPHP) {
       this.containerPHP = containerPHP;
       }
      
       public ArrayList<Framework> getFrameworks() {
       if (frameworks == null) {
       initList();
       }
       return frameworks;
       }
      
       public void setFrameworks(ArrayList<Framework> frameworks) {
       this.frameworks = frameworks;
       }
      
       public void moveFramework(Object fm, Object family) {
       ArrayList<Framework> target = null;
       if ("PHP".equals(family)) {
       target = containerPHP;
       } else if ("DNET".equals(family)) {
       target = containerDNET;
       } else if ("CF".equals(family)) {
       target = containerCF;
       }
       if (target != null) {
       int ind = frameworks.indexOf(fm);
       if (ind > -1) {
       target.add(frameworks.get(ind));
       frameworks.remove(ind);
       }
       }
       }
      
       public String reset() {
       initList();
       return null;
       }
      
       private void initList() {
       frameworks = new ArrayList<Framework>();
       frameworks.add(new Framework("Flexible Ajax", "PHP"));
       frameworks.add(new Framework("ajaxCFC", "CF"));
       frameworks.add(new Framework("AJAXEngine", "DNET"));
       frameworks.add(new Framework("AjaxAC", "PHP"));
       frameworks.add(new Framework("MonoRail", "DNET"));
       frameworks.add(new Framework("wddxAjax", "CF"));
       frameworks.add(new Framework("AJAX AGENT", "PHP"));
       frameworks.add(new Framework("FastPage", "DNET"));
       frameworks.add(new Framework("JSMX", "CF"));
       frameworks.add(new Framework("PAJAJ", "PHP"));
       frameworks.add(new Framework("Symfony", "PHP"));
       frameworks.add(new Framework("PowerWEB", "DNET"));
       containerPHP = new ArrayList<Framework>();
       containerCF = new ArrayList<Framework>();
       containerDNET = new ArrayList<Framework>();
       }
      }
      


      EventBean.java

      import org.richfaces.component.Dropzone;
      import org.richfaces.event.DropEvent;
      import org.richfaces.event.DropListener;
      
      
      public class EventBean implements DropListener {
      
       private gwkinfo.DndBean dndBean;
       public void processDrop(DropEvent dropEvent) {
       Dropzone dropzone = (Dropzone) dropEvent.getComponent();
       dndBean.moveFramework(dropEvent.getDragValue(),dropzone.getDropValue());
       }
       public gwkinfo.DndBean getDndBean() {
       return dndBean;
       }
       public void setDndBean(gwkinfo.DndBean dndBean) {
       this.dndBean = dndBean;
       }
       }
      


      Framework.java
      public class Framework {
       private String name;
       private String family;
      
       public String getFamily() {
       return family;
       }
       public void setFamily(String family) {
       this.family = family;
       }
       public String getName() {
       return name;
       }
       public void setName(String name) {
       this.name = name;
       }
       public Framework(String name, String family) {
       super();
       this.name = name;
       this.family = family;
       }
       }
      


      And my dnd.xhtml:

      <ui:composition 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">
      
      
       <style>
       .panelc {
       width:25%;
       vertical-align:top;
       }
      
       .dropTargetPanel {
       width: 90%;
       }
      
       .footerClass {
       text-align: center;
       padding-top: 5px;
       }
      
       </style>
      
       <rich:dragIndicator id="indicator"/>
      
       <h:form id="form">
      
       <h:panelGrid columnClasses="panelc" columns="4" width="100%">
      
       <rich:panel style="width:133px">
       <f:facet name="header">
       <h:outputText value="Source List" />
       </f:facet>
       <h:dataTable id="src" columns="1" value="#{dndBean.frameworks}"
       var="fm" footerClass="footerClass">
       <h:column>
      
       <a4j:outputPanel style="width:100px;border:1px solid gray;padding:2px"
       layout="block">
      
       <rich:dragSupport dragIndicator=":indicator"
       dragType="#{fm.name}" dragValue="#{fm}">
       <rich:dndParam name="label" value="#{fm.name}" />
       </rich:dragSupport>
       <h:outputText value="#{fm.name}"></h:outputText>
       </a4j:outputPanel>
       </h:column>
       <f:facet name="footer">
       <a4j:commandButton action="#{dndBean.reset}" value="Start Over" reRender="src,phptable,cftable,dnettable"/>
       </f:facet>
       </h:dataTable>
       </rich:panel>
      
       <rich:panel styleClass="dropTargetPanel">
       <f:facet name="header">
       <h:outputText value="PHP Frameworks" />
       </f:facet>
       <rich:dropSupport id="php" acceptedTypes="PHP" dropValue="PHP"
       dropListener="#{eventBean.processDrop}" reRender="phptable, src">
       </rich:dropSupport>
      
       <h:dataTable id="phptable" columns="1" value="#{dndBean.containerPHP}" var="fm">
       <h:column>
       <h:outputText value="#{fm.name}"></h:outputText>
       </h:column>
       </h:dataTable>
      
      
       </rich:panel>
      
       <rich:panel styleClass="dropTargetPanel">
       <f:facet name="header">
       <h:outputText value=".NET Frameworks" />
       </f:facet>
       <rich:dropSupport id="dnet" acceptedTypes="DNET" dropValue="DNET"
       dropListener="#{eventBean.processDrop}" reRender="dnettable, src">
       </rich:dropSupport>
      
       <h:dataTable id="dnettable" columns="1" value="#{dndBean.containerDNET}" var="fm">
       <h:column>
       <h:outputText value="#{fm.name}"></h:outputText>
       </h:column>
       </h:dataTable>
      
      
       </rich:panel>
      
       <rich:panel styleClass="dropTargetPanel">
       <f:facet name="header">
       <h:outputText value="ColdFusion Frameworks" />
       </f:facet>
       <rich:dropSupport id="cf" acceptedTypes="CF" dropValue="CF"
       dropListener="#{eventBean.processDrop}" reRender="cftable, src">
       </rich:dropSupport>
      
       <h:dataTable id="cftable" columns="1" value="#{dndBean.containerCF}" var="fm">
       <h:column>
       <h:outputText value="#{fm.name}"></h:outputText>
       </h:column>
       </h:dataTable>
       </rich:panel>
       </h:panelGrid>
      
       </h:form>
       <a4j:outputPanel ajaxRendered="true">
       <h:messages></h:messages>
       </a4j:outputPanel>
      </ui:composition>
      


      What im doing wrong? I need help!
      Im using Richfaces 3.3.0 Beta 2
      In my faces.config.xml is this code for my Beans:
      <managed-bean>
       <managed-bean-name>fm</managed-bean-name>
       <managed-bean-class>gwkinfo.Framework</managed-bean-class>
       <managed-bean-scope>session</managed-bean-scope>
       </managed-bean>
       <managed-bean>
       <managed-bean-name>eventBean</managed-bean-name>
       <managed-bean-class>gwkinfo.EventBean</managed-bean-class>
       <managed-bean-scope>session</managed-bean-scope>
       </managed-bean>
       <managed-bean>
       <managed-bean-name>dndBean</managed-bean-name>
       <managed-bean-class>gwkinfo.DndBean</managed-bean-class>
       <managed-bean-scope>session</managed-bean-scope>
       </managed-bean>
      


      Thank you in advanced.
      Leila

        • 1. Re: Drag and Drop problem
          Nick Belaevski Master

          Hi Leila,

          1. remove "fm" managed bean
          2. add html/body tags
          3. dragType should be #{fm.family} and not #{fm.name}

          • 2. Re: Drag and Drop problem
            marek kocjev Newbie

             

            "nbelaevski" wrote:
            Hi Leila,

            1. remove "fm" managed bean
            2. add html/body tags
            3. dragType should be #{fm.family} and not #{fm.name}


            Thank you, now i get this:

            javax.servlet.ServletException: /pages/dnd.xhtml @63,86 dropListener="#{eventBean.processDrop}": java.lang.NullPointerException

            Maybe i have some error in my EventBean.java ?


            • 3. Re: Drag and Drop problem
              marek kocjev Newbie

               

              "leila84" wrote:
              "nbelaevski" wrote:
              Hi Leila,

              1. remove "fm" managed bean
              2. add html/body tags
              3. dragType should be #{fm.family} and not #{fm.name}


              Thank you, now i get this:

              javax.servlet.ServletException: /pages/dnd.xhtml @63,86 dropListener="#{eventBean.processDrop}": java.lang.NullPointerException

              Maybe i have some error in my EventBean.java ?


              Ok, i have this example running now.
              I have downloaded a newer war-file.

              Bye,
              Leila

              • 4. Re: Drag and Drop problem
                Lindalva Santos Newbie

                Hi,

                I'm trying this exemple, but I still can't make it works.

                Using IE, there is no error, but nothing happens after I drop some item. Using Firefox, after drop the page returns a NullPointerException.

                Someone can help me please ?