svn changeset:18078/svn branch:6.6tags/6.7.0.beta1
@@ -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")) { |
@@ -97,6 +97,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. | |||
* | |||
@@ -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. |
@@ -0,0 +1,73 @@ | |||
package com.vaadin.tests.components.upload; | |||
import java.io.ByteArrayOutputStream; | |||
import java.io.OutputStream; | |||
import com.vaadin.tests.components.TestBase; | |||
import com.vaadin.ui.Button; | |||
import com.vaadin.ui.Button.ClickListener; | |||
import com.vaadin.ui.Upload; | |||
import com.vaadin.ui.Button.ClickEvent; | |||
import com.vaadin.ui.Upload.FailedEvent; | |||
import com.vaadin.ui.Upload.FinishedEvent; | |||
import com.vaadin.ui.Upload.Receiver; | |||
public class ForceSubmit extends TestBase implements Receiver { | |||
@Override | |||
protected Integer getTicketNumber() { | |||
return 6630; | |||
} | |||
public OutputStream receiveUpload(String filename, String MIMEType) { | |||
return new ByteArrayOutputStream(); | |||
} | |||
@Override | |||
protected void setup() { | |||
final Upload u; | |||
u = new Upload("Upload", this); | |||
u.setButtonCaption(null); | |||
addComponent(u); | |||
u.addListener(new Upload.FinishedListener() { | |||
public void uploadFinished(FinishedEvent event) { | |||
String filename = event.getFilename(); | |||
long length = event.getLength(); | |||
getMainWindow().showNotification( | |||
"Done. Filename : " + filename + " Lenght: " + length); | |||
} | |||
}); | |||
u.addListener(new Upload.FailedListener() { | |||
public void uploadFailed(FailedEvent event) { | |||
getMainWindow().showNotification("Failed. No file selected?"); | |||
} | |||
}); | |||
Button button = new Button( | |||
"I'm an external button (not the uploads builtin), hit me to start upload."); | |||
button.addListener(new ClickListener() { | |||
public void buttonClick(ClickEvent event) { | |||
u.submitUpload(); | |||
} | |||
}); | |||
addComponent(button); | |||
} | |||
@Override | |||
protected String getDescription() { | |||
return "Some wireframists are just so web 1.0. If requirements " + | |||
"say the upload must not start until the whole form " + | |||
"is 'Oukeyd', that is what we gotta do. In these cases " + | |||
"developers most probably also want to hide the uploads" + | |||
" internal button by setting its caption to null."; | |||
} | |||
} |