2 Replies Latest reply on May 16, 2008 11:11 AM by youngkin

    DragIndicator not visible

    youngkin

      Ack! I'm stuck...

      I've read thru the developer's guide and various posts I found on this topic, but to no avail. I'm trying to adapt the live demo drag-n-drop example code. The problem is that the Drag Indicator isn't visible. The dropListener method isn't being called, so I'm assuming that "drag" isn't working at all.

      Here's my .xhtml file

      <!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">
      
      <ui:composition template="battleshpGameTemplate.xhtml">
       <rich:dragIndicator id="indicator" />
       <ui:define name="uiBoard">
       <h:form method="post">
       <h:panelGrid columns="2">
       <f:facet name="header">Game Board</f:facet>
       <rich:panel>
       <f:facet name="header">
       <h:outputText value="Game Pieces" />
       </f:facet>
       <h:dataTable id="gamePieces" columns="1"
       value="#{gameBoardBean.gamePieces}" var="gp"
       footerClass="footerClass">
       <h:column>
       <a4j:outputPanel
       style="width:100px;border:1px solid gray;padding:2px"
       layout="block">
       <rich:dragSupport dragIndicator=":indicator"
       dragType="GamePiece" dragValue="#{gp}">
       <rich:dndParam name="label" value="#{gp}" />
       </rich:dragSupport>
       <h:outputText value="#{gp}"></h:outputText>
       </a4j:outputPanel>
       </h:column>
       <f:facet name="footer">
       <a4j:commandButton action="#{gameBoardBean.resetBoard}"
       value="Start Over"
       reRender="gamePieces,one_one" />
       </f:facet>
       </h:dataTable>
       </rich:panel>
      
       <h:panelGrid columns="">
       <table>
       <tr>
       <td><rich:panel styleClass="dropTargetPanel">
       <rich:dropSupport id="one_one" acceptedTypes="GamePiece"
       dropValue="GamePiece"
       dropListener="#{gameBoardBean.processDrop}"
       reRender="one_one,gamePieces">
       </rich:dropSupport>
      
       <h:dataTable id="one_oneTable" columns="1"
       value="#{gameBoardBean.board}" var="board">
       <h:column>
       <h:outputText value="#{board}"></h:outputText>
       </h:column>
       </h:dataTable>
       </rich:panel></td>
       </tr>
       </table>
       </h:panelGrid>
      
       </h:panelGrid>
       <p><h:commandButton value="#{dWRFD1.back}"
       action="#{gameBoardBean.processResult}" style="width: 6em" />
       </p>
       </h:form>
       </ui:define>
      </ui:composition>
      </html>


      Here's the associated bean code:

      package com.dW;
      
      import java.util.ArrayList;
      
      import javax.faces.context.FacesContext;
      
      import org.richfaces.event.DropEvent;
      import org.richfaces.component.Dropzone;
      
      public class GameBoardBean
      {
       private ArrayList<String> mGamePiecesContainer = new ArrayList();
       private String[][] mBoard = new String[2][2];
      
       public GameBoardBean()
       {
       resetBoard();
       }
      
       public void resetBoard()
       {
       mGamePiecesContainer.add("Battleship");
       mGamePiecesContainer.add("Destroyer");
       mGamePiecesContainer.add("Carrier");
       mGamePiecesContainer.add("Cruiser");
      
       for (int i = 0; i < 2; i++)
       {
       for (int j = 0; j < 2; j++)
       {
       mBoard[j] = null;
       }
       }
       }
      
       public String processResult()
       {
       return "back";
       }
      
       public void processDrop(DropEvent dropEvent)
       {
       mBoard[0][0] = (String) dropEvent.getDragValue();
       for (int i = 0; i < mGamePiecesContainer.size(); i++)
       {
       String val = mGamePiecesContainer.get(i);
       if (val.equalsIgnoreCase(mBoard[0][0]))
       {
       mGamePiecesContainer.remove(i);
       break;
       }
       }
       }
      
       /**
       * @return the board
       */
       public String[][] getBoard()
       {
       return mBoard;
       }
      
       /**
       * @param aBoard the board to set
       */
       public void setBoard(String[][] aBoard)
       {
       mBoard = aBoard;
       }
      
       /**
       * @return the gamePiecesContainer
       */
       public ArrayList<String> getGamePieces()
       {
       return mGamePiecesContainer;
       }
       }


      Thanks,
      Rich