Important Notice - Forums is archived

To simplify things and help our users to be more productive, we have archived the current forum and focus our efforts on helping developers on Stack Overflow. You can post new questions on Stack Overflow or join our Discord channel.

Product icon

Vaadin lets you build secure, UX-first PWAs entirely in Java.
Free ebook & tutorial.

Upload component - how to I choose a file before invoking submitUpload()?

David Green
1 decade ago Apr 04, 2012 9:44am


I'm trying to create a custom upload dialogue positioning a button slightly differently to the default implementation. In my Button.ClickListener I have an upload.submitUpload() call, however a button appears on the for saying 'choose file'. How can avoid displaying this button and invoke the (file open) 'chooser' and/or set the filename I want to upload?

Also if there is an error I get a stack-trace on the UI - I thought I could wrap my button in an exception handler to avoid this but since the stack trace never includes my own classes I don't know how to put in an exception handling hook (/listener). What is the best way to do this?



public class UploadComponent extends Window implements Upload.SucceededListener, Upload.FailedListener, Upload.Receiver, Upload.StartedListener, Upload.ProgressListener {

    private Upload upload = new Upload("", this);

    private Panel panel = null; // element for containing components
    private VerticalLayout v = new VerticalLayout();

    private Button submitButton = new Button("Upload...");

    private static final Logger log = LogUtil.getLogger();

    private Button.ClickListener submitButtonClickListener = new Button.ClickListener() {
        public void buttonClick(Button.ClickEvent event) {
            try {
                log.info("Clicked submit");
            catch (Exception ex) {
                log.error("Caught exception after submit");
    public UploadComponent() {

        upload.setImmediate(true); // Upload immediately


        upload.setButtonCaption(null); // Set the caption to null hides the upload button

        upload.addListener((Upload.StartedListener) this);
        upload.addListener((Upload.ProgressListener) this);
        upload.addListener((Upload.SucceededListener) this);
        upload.addListener((Upload.FailedListener) this);




Last updated on Apr, 4th 2012