I am having an issue making drag n drop work which is now getting critical for a client demo next week. Having not used this in the past I downloaded the example from the Servoy SVN and tested solution items 1-4 work perfectly, however the key element I need is to be able to drag files from the users file system onto Servoy, record the file name and trigger a streaming upload to the server. I have tried the DNDFileBean from I think Servoy Forge, however it would appear certainly in later versions of Servoy this is not necessary.
On the basis the SVN demo file failed I decided to build a super basic form with a single Label called Test
I have enabled the drag and drop with the following on the form
I have a label named Test (incidentally i also tried it with a field and variables called Test)
I have a Drag Over script enabled as follows
function onDragOver(event) {
application.output(event)
if (event.getElementName() == 'Test' && event.data)
{
application.output('dragged over')
return true;
}
return false;
}
and I have a drop script
function onDrop(event) {
// TODO Auto-generated method stub
application.output('dropped')
return false
}
The questions are:
a) Should this at least trigger the fact that item was dragged over i.e. output something from the event
b) Am I barking up the wrong tree all together
c) Does anyone have a working example because the Servoy version does not seem to work in example 5
I have tried this in both Servoy 6 final and 5.2.9
In Servoy 6 dropping files is supported, in Servoy 5 you need the bean.
The problem is the event.data that you receive. It is a native type: java.util.List<java.io.File>, meaning basically it is a list of files.
Look at these two methods:
function onDragOver(event) {
if (event.getSource() && event.data) {
if (event.data instanceof java.util.List && event.data.size() > 0 && event.data.get(0) instanceof java.io.File) {
//event.data contains a List of files
return true;
}
}
// only files allowed in this example
return false;
}
and
function onDrop(event) {
if (event.getSource() && event.data) {
if (event.data instanceof java.util.List && event.data.size() > 0 && event.data.get(0) instanceof java.io.File) {
// we have a List of items
for (var i = 0; i < event.data.size(); i++) {
var vJsFile = plugins.file.convertToJSFile(event.data.get(i).getAbsolutePath());
application.output(vJsFile.getAbsolutePath());
}
return true;
}
}
return false;
}
Note that a List is not an array. To see what you can do with a List, check this http://download.oracle.com/javase/6/doc … /List.html. Basically, I think you will need only List.size() and List.get(index) where Lists are zero based.
Thanks Patrick - that makes sense and would explain why the demo failed as I think its about 12-14 months old.
I think Servoy need to consider setting up a group of developers who could update the various demos for each iteration, or at least test that the features contained are using the current technology rather than depreciated older version.