diff options
author | Matti Tahvonen <matti.tahvonen@itmill.com> | 2011-04-01 12:42:12 +0000 |
---|---|---|
committer | Matti Tahvonen <matti.tahvonen@itmill.com> | 2011-04-01 12:42:12 +0000 |
commit | d2c22fbd5b9d5db89c94bfd9b65d026aa71b9352 (patch) | |
tree | 56f56878ddb33cfbe8695aa7580ceb9162a92b91 /src | |
parent | dedbcc13457d92662499198ee9d33ff6b7ab0989 (diff) | |
download | vaadin-framework-d2c22fbd5b9d5db89c94bfd9b65d026aa71b9352.tar.gz vaadin-framework-d2c22fbd5b9d5db89c94bfd9b65d026aa71b9352.zip |
#6630 forcing upload start now possible with java api. Also (related to this) setting uploadButtonCaption to null, hides the upload button (this way there is no need to use css for this).
svn changeset:18078/svn branch:6.6
Diffstat (limited to 'src')
-rw-r--r-- | src/com/vaadin/terminal/gwt/client/ui/VUpload.java | 11 | ||||
-rw-r--r-- | src/com/vaadin/ui/Upload.java | 51 |
2 files changed, 60 insertions, 2 deletions
diff --git a/src/com/vaadin/terminal/gwt/client/ui/VUpload.java b/src/com/vaadin/terminal/gwt/client/ui/VUpload.java index f267f97860..ddca44d7d4 100644 --- a/src/com/vaadin/terminal/gwt/client/ui/VUpload.java +++ b/src/com/vaadin/terminal/gwt/client/ui/VUpload.java @@ -143,12 +143,21 @@ public class VUpload extends SimplePanel implements Paintable { t.schedule(400); return; } + if(uidl.hasAttribute("forceSubmit")) { + element.submit(); + return; + } setImmediate(uidl.getBooleanAttribute("immediate")); this.client = client; paintableId = uidl.getId(); nextUploadId = uidl.getIntAttribute("nextid"); element.setAction(uidl.getStringVariable("action")); - submitButton.setText(uidl.getStringAttribute("buttoncaption")); + if(uidl.hasAttribute("buttoncaption")) { + submitButton.setText(uidl.getStringAttribute("buttoncaption")); + submitButton.setVisible(true); + } else { + submitButton.setVisible(false); + } fu.setName(paintableId + "_file"); if (uidl.hasAttribute("disabled") || uidl.hasAttribute("readonly")) { diff --git a/src/com/vaadin/ui/Upload.java b/src/com/vaadin/ui/Upload.java index 51de029108..3928f809f3 100644 --- a/src/com/vaadin/ui/Upload.java +++ b/src/com/vaadin/ui/Upload.java @@ -98,6 +98,11 @@ public class Upload extends AbstractComponent implements Component.Focusable { private int nextid; /** + * Flag to indicate that submitting file has been requested. + */ + private boolean forceSubmit; + + /** * Creates a new instance of Upload. * * The receiver must be set before performing an upload. @@ -143,6 +148,11 @@ public class Upload extends AbstractComponent implements Component.Focusable { notStarted = false; return; } + if (forceSubmit) { + target.addAttribute("forceSubmit", true); + forceSubmit = true; + return; + } // The field should be focused if (focus) { target.addAttribute("focus", true); @@ -155,7 +165,9 @@ public class Upload extends AbstractComponent implements Component.Focusable { target.addAttribute("state", isUploading); - target.addAttribute("buttoncaption", buttonCaption); + if (buttonCaption != null) { + target.addAttribute("buttoncaption", buttonCaption); + } target.addAttribute("nextid", nextid); @@ -901,6 +913,15 @@ public class Upload extends AbstractComponent implements Component.Focusable { * In addition to the actual file chooser, upload components have button * that starts actual upload progress. This method is used to set text in * that button. + * <p> + * In case the button text is set to null, the button is hidden. In this + * case developer must explicitly initiate the upload process with + * {@link #submitUpload()}. + * <p> + * In case the Upload is used in immediate mode using + * {@link #setImmediate(boolean)}, the file choose (html input with type + * "file") is hidden and only the button with this text is shown. + * <p> * * <p> * <strong>Note</strong> the string given is set as is to the button. HTML @@ -915,6 +936,34 @@ public class Upload extends AbstractComponent implements Component.Focusable { requestRepaint(); } + /** + * Forces the upload the send selected file to the server. + * <p> + * In case developer wants to use this feature, he/she will most probably + * want to hide the uploads internal submit button by setting its caption to + * null with {@link #setButtonCaption(String)} method. + * <p> + * Note, that the upload runs asynchronous. Developer should use normal + * upload listeners to trac the process of upload. If the field is empty + * uploaded the file name will be empty string and file length 0 in the + * upload finished event. + * <p> + * Also note, that the developer should not remove or modify the upload in + * the same user transaction where the upload submit is requested. The + * upload may safely be hidden or removed once the upload started event is + * fired. + */ + public void submitUpload() { + requestRepaint(); + forceSubmit = true; + } + + @Override + public void requestRepaint() { + forceSubmit = false; + super.requestRepaint(); + } + /* * Handle to terminal via Upload monitors and controls the upload during it * is being streamed. |