diff options
author | Artur Signell <artur@vaadin.com> | 2013-02-08 09:40:25 +0200 |
---|---|---|
committer | Artur Signell <artur@vaadin.com> | 2013-02-08 09:41:58 +0200 |
commit | 613d2c044d1c3dfeeb54112e3030dbe62282e1fc (patch) | |
tree | b137000d48536964399543eee74c7629e2918306 /client | |
parent | 77aed50851264cf89025fcf0a082e83027d90f68 (diff) | |
download | vaadin-framework-613d2c044d1c3dfeeb54112e3030dbe62282e1fc.tar.gz vaadin-framework-613d2c044d1c3dfeeb54112e3030dbe62282e1fc.zip |
Fixed race condition in upload (#10942)
Updated test to show if upload succeeds or fails
Change-Id: Ia9c3a3d36a5dd163fbad59e8cc41d53aba3ccb5a
Diffstat (limited to 'client')
-rw-r--r-- | client/src/com/vaadin/client/ui/VUpload.java | 50 |
1 files changed, 31 insertions, 19 deletions
diff --git a/client/src/com/vaadin/client/ui/VUpload.java b/client/src/com/vaadin/client/ui/VUpload.java index f639e8f090..866a6ca4cf 100644 --- a/client/src/com/vaadin/client/ui/VUpload.java +++ b/client/src/com/vaadin/client/ui/VUpload.java @@ -18,6 +18,7 @@ package com.vaadin.client.ui; import com.google.gwt.core.client.GWT; import com.google.gwt.core.client.Scheduler; +import com.google.gwt.core.client.Scheduler.ScheduledCommand; import com.google.gwt.dom.client.DivElement; import com.google.gwt.dom.client.Document; import com.google.gwt.dom.client.FormElement; @@ -257,6 +258,32 @@ public class VUpload extends SimplePanel { }); } + ScheduledCommand startUploadCmd = new ScheduledCommand() { + + @Override + public void execute() { + element.submit(); + submitted = true; + + disableUpload(); + + /* + * Visit server a moment after upload has started to see possible + * changes from UploadStarted event. Will be cleared on complete. + */ + t = new Timer() { + @Override + public void run() { + VConsole.log("Visiting server to see if upload started event changed UI."); + client.updateVariable(paintableId, "pollForStart", + nextUploadId, true); + } + }; + t.schedule(800); + } + + }; + /** For internal use only. May be removed or replaced in the future. */ public void submit() { if (fu.getFilename().length() == 0 || submitted || !enabled) { @@ -267,25 +294,10 @@ public class VUpload extends SimplePanel { // before upload client.sendPendingVariableChanges(); - element.submit(); - submitted = true; - VConsole.log("Submitted form"); - - disableUpload(); - - /* - * Visit server a moment after upload has started to see possible - * changes from UploadStarted event. Will be cleared on complete. - */ - t = new Timer() { - @Override - public void run() { - VConsole.log("Visiting server to see if upload started event changed UI."); - client.updateVariable(paintableId, "pollForStart", - nextUploadId, true); - } - }; - t.schedule(800); + // This is done as deferred because sendPendingVariableChanges is also + // deferred and we want to start the upload only after the changes have + // been sent to the server + Scheduler.get().scheduleDeferred(startUploadCmd); } @Override |