DataTransfer getData

80 views
Skip to first unread message

Ronit

unread,
May 14, 2023, 6:57:20 PM5/14/23
to GWT Users
Hello Team,

I am new to GWT and working on an existing code. I am trying to implement a drag and drop functionality .I am having issues getting data from DataTransfer object. I need to drag and drop any file from the computer on the widget.

 grid.addDropHandler(new DropHandler() {
            @Override
            public void onDrop(DropEvent event) {
                event.preventDefault();
                DataTransfer dataTransfer = event.getNativeEvent().getDataTransfer();
                dataTransfer.setDropEffect(DropEffect.COPY);
                Object data = dataTransfer.getData("File");
             }
        });


I am getting an empty-string on  dataTransfer.getData("file")'
How can we set the format "File" while doing dataTransfer.setData();
I think I am doing something wrong here . Please advice. 

Thank you
Ronit

Thomas Broyer

unread,
May 16, 2023, 3:26:04 AM5/16/23
to GWT Users
AFAICT, this is not how you handle file drops: https://developer.mozilla.org/en-US/docs/Web/API/HTML_Drag_and_Drop_API/File_drag_and_drop
and GWT's drag and drop API doesn't support what's needed here. You'd have to use Elemental2 (com.google.elemental2:elemental2-dom) which should have everything.

Reply all
Reply to author
Forward
0 new messages