I’m trying to use the Upload component to browse and upload a file in a form. What I want is a “browse”-part and the upload-functionality, but not the upload button. I need the browse textfield because users can add the filename manual, so immediate won’t work for me. I need the browse-button for obvious reasons.
After selecting the file to upload, the user needs to add several other things and than clicks a submit button. The moment the submit button is clicked I want to execute the actual upload. How do I excute/start the upload without using the upload button?
It is also OK to upload the file while the user is entering other data, like in immediate, but I do need the possibility for the user to add the file location manually.
btw i made the upload button invisible via the CSS using
.myupload .v-button,
.myupload .v-button .v-button-wrap {
visibility: hidden;
}
It seems what you can get is an upload that is immediate, yet the user can enter a new name for the file instead of the one in his/her computer.
This you could do by,
Set Upload Immediate, that means you lose the browse part (which looks differently on each browser) .
Create custom field , that is implement Field , you can use
CustomField , the field will contain a textfield and upload. Change the caption of uploadBtn to say “Browser…” or whatever.
Once the upload is done, you set the filename to the textfield which the user can then change. Subsequently when you commit your form you’ll get the filename from the textfield instead.
And check the
upload api there is startUpload and other methods you might have overlooked.
The problem is that I do not want the file to upload immediately. I just want to choose a file and later upload it on the click of another button.
I did try startUpload() and fireStarted(filename, mtype) methods of the upload component but none of them does the trick:(
For future reference, since Vaadin 6.6 there is now the startUpload() method which can be used in conjunction with the setButtonCaption(null) method that will simply hide the default upload button but not set the component in
immediate mode.
I can’t get it working :-(. When button caption is set to null, my receiveUpload(String filename, String mimeType) method is never called; not after calling upload.submitUpload(), nor upload.startUpload().
When the Upload button is visible, the method is called immediately, after clicking it.
void com.vaadin.ui.Upload.startUpload()
Go into upload state. This is to prevent double uploading on same component. Warning: this is an internal method used by the framework and should not be used by user of the Upload component. Using it results in the Upload component going in wrong state and not working. It is currently public because it is used by another class.
I got this working today (v7.1.9). You want to use .submitUpload(). This will trigger the appropriate callbacks. Here’s the important bits:
For the uploader:
Upload upload = new Upload("Pick a file", myUploadListener);
upload.addSucceededListener(myUploadListener);
upload.addFailedListener(myUploadListener);
upload.addProgressListener(myUploadListener);
[b]
upload.setButtonCaption(null);
[/b]
For the submit button handler:
private class SubmitButtonClickListener implements ClickListener{
private static final long serialVersionUID = 1L;
@Override
public void buttonClick(ClickEvent event) {
[b]
upload.submitUpload();
[/b]
}
}
If you don’t actually select a file, nothing gets triggered.
which Datatype a bean property have to has, if you want to use the BeanFieldGroup and build a UploadField with the method
buildAndBind(caption, propertyId, Field) ?
Hi,
I wants to set description to single button upload component after sucessful upload.
I tried:
public void uploadSucceeded(Upload.SucceededEvent event) {
try {
// Log the upload on screen.
log.info(“File " + event.getFilename() + " of type '”
+ event.getMIMEType() + “’ uploaded.”);
upload.setDescription(“File " + event.getFilename()
+ " is uploaded.”);
} catch (Exception excp) {
log.error(excp.getMessage(), excp);
}
}
But still its not working.
On mouse hover of that upload button its showing "
No Files Uploaded "