O'Reilly logo

Vaadin 7 UI Design By Example Beginner's Guide by Alejandro Duarte

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

File download

In Chapter 2, Using Input Components and Forms – Time to Listen to Users, we learned how to upload files. Now we're going to learn how to download files. Let's say we have a PDF file and want users to download it by clicking a button. Doing it is quite easy. First a PDF file is a Resource, right? Suppose the file is in the classpath:

ClassResource resource = new ClassResource("enterprise-app.pdf");

We also need a Button:

Button button = new Button("Download the PDF");
button.setStyleName(BaseTheme.BUTTON_LINK);

Tip

Use button.setStyleName(BaseTheme.BUTTON_LINK) to render the button like a standard link. Next chapter we'll learn more about styles.

The following two lines will make the rest of the job:

FileDownloader downloader = new FileDownloader(resource); ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required