DnD - How to have DragDropEvent.getData() not null

UI Components for JSF
Post Reply
mask_hot
Posts: 34
Joined: 27 May 2011, 10:52

01 Sep 2011, 01:34

I'm trying to do some stuff as your Football Manager DnD example, but a little bit more complicated and I have a question : what are the requirements to have DragDropEvent.getData() not null in onDrop listener?

Is this condition only available for Datable and/or DataGrid, or is it possible to get/put some data from/in a draggable/droppable element?

Code: Select all


<p:panel header="Field"  styleClass="soccer_field">  
            <p:dataGrid id="trgField" value="#{famFormationController.lstTarget}" 
                        var="t" columns="5" 
                        style="padding-top: 25px;margin-left: 20px;">     
                <p:column>  
                    <p:panel header="#{t.strIdx}" id="trg" 
                             style="display:block;text-align:center;width:50px;height:63px;border:1px solid #666666;">
                        <p:panel id="item" 
                                 rendered="#{!empty t.famFormationItem.numItem}">
                            <h:outputText value="#{t.famFormationItem.numItem}"/> 
                        </p:panel>
                        <p:draggable for="item" revert="true" handle=".ui-panel-titlebar" stack=".ui-panel" /> 

                    </p:panel>
                    <p:droppable for="trg"
                                 tolerance="touch"
                                 activeStyleClass="slotActive" 

                                 onDrop="handleDrop"
                                 >
                        <p:ajax listener="#{famFormationController.onDrop}" 
                                update="@form"
                                />  
                    </p:droppable>
                </p:column>  
            </p:dataGrid>  
        </p:panel>  

Code: Select all

public void onDrop(DragDropEvent event) {
FamFormationItem item = (FamFormationItem) event.getData(); 
// or anything else... for now  event.getData() is always null
}
As I have many draggable and droppable elements, I wish I knew which one I'm dragging and dropping on wich other one (but not only the DOM id, the Java Object would be nicer :D )

I hope I was clear... :D

mask_hot
Posts: 34
Joined: 27 May 2011, 10:52

01 Sep 2011, 23:30

Ok, just found it... simply add the good datasource attribute...

Post Reply

Return to “PrimeFaces”

  • Information
  • Who is online

    Users browsing this forum: Google [Bot] and 36 guests