Upload control with empty selection

Hi, I have a problem using the Upload control.

In a “page” of my app, the user writes a message and may or may not attach a file. Then he sends both the message and the file by an “Ok button” (this makes the logic of my app much cleaner).
I need to understand whether the user has choosen a file or not, and, in any case, when all the operation is finished (I have to save the message and the eventual attachment in a database). Unfortunately the upload control doesn’t expose the chosen filename (by design, if I understand well), so I need to listen to some events.

According to the doc:


The relevant code of my app is:

// window containing the upload control(s)
public class MyModalWindow extends Window implements 
Upload.SucceededListener, Upload.FailedListener, Upload.Receiver, 
Upload.StartedListener, Upload.FinishedListener
Upload myUploadCtrl =null;

// implement listeners
public void uploadFinished(FinishedEvent event)
	// do something here
// and so on with other listeners

// control creation (without "submit" button)
myUploadCtrl = new Upload("", this);
myUploadCtrl.setButtonCaption(null); // hide "submit" button
myUploadCtrl.addListener((Upload.SucceededListener) this);
myUploadCtrl.addListener((Upload.FailedListener) this);
myUploadCtrl.addListener((Upload.FinishedListener) this);
myUploadCtrl.addListener((Upload.StartedListener) this);

// start upload by pressing Ok button
void onOk()

the problem is: when I choose a file, the listeners are correctly called, but if no file is selected, the listeners are not called (despite what is written in the documentation. If I understand well, when the selection is empty the listeners should be called with an empty filename and filelength=0).

Any idea?
Thank you in advance.


I have the same problem too, despite what’s documented in the documentation. Any solution so far?

This is either a documentation or functionality bug; please submit a ticket to our

. Thanks!

The simplest solution to this problem would be defining a method such as:

boolean isSelectionEmpty();

if the selection is empty, the programmer simply doesn’t listen to any event.

S Sui: my temporary, non optimal solution for this problem is the following.

I have created a new control composed by a checkbox and an upload control. When the checkbox is unchecked, the upload is disabled (this is the initial state). So the user has to check the checkbox and, hopefully, choose the file. You retrieve the checkbox status to decide if you need to wait for the file.
Of course that’s not “idiot proof”, because the user could check the checkbox and NOT choose any file, by anyway it works in most cases.

Hope it helps.