3

I'm trying to use the Upload component to browse and upload a file i. What I want is only upload-functionality, but not the upload button and the browse button.I want to add a button to the page when a user click it the browse file window is opened so he can choose a file and upload it I wrote this :

@Override
protected void init(VaadinRequest request) {
    final VerticalLayout layout = new VerticalLayout();
    layout.setMargin(true);
    setContent(layout);
    final Upload sample = new Upload(null, null);
    Button button = new Button("Click Me");
    sample.setImmediate(true);
            sample.setButtonCaption(null);
            System.out.println(sample.isVisible());
    button.addClickListener(new Button.ClickListener() {
        public void buttonClick(ClickEvent event) {
            layout.addComponent(new Label("Thank you for clicking"));
            sample.setVisible(true);
            layout.addComponent(sample);
        }
    });
    layout.addComponent(button);
  }

 }

1 Answer 1

3

You want a single-click upload. There is no need for an extra button.

// Make uploading start immediately when file is selected
upload.setImmediate(true);
upload.setButtonCaption("Select file");

Example here.

Sign up to request clarification or add additional context in comments.

3 Comments

thank u @nexus but i really need the extra button i have to create by myself and lunch the browse window when the user click it
@AmiraGL why not using this solution? Or do I missunderstand something?
The upload.setButtonCaption("Select file"); already exists in the page, i will create a custom widget for this ;)

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.