How I use app.getMainWindow().open(resource, target) on vaadin 7?

Hi, everyone.

I’m developing a exporter to pdf for vaadin components.
I’m having a problem when it comes to download the pdf.
At first, I wanted to show the pdf on a browser’s new window and then the user have the option to download it or not. But , now I just want It to be downloaded right away.
On vaadin 6, I found thoses methods : app.getMainWindow().open(resource, target).

I want to know, how I do the same things, but on vaadin 7?

Hello Victor!

If you want to download the generated file, this should help you get started:

http://vaadin.com/wiki/-/wiki/Main/Letting+the+user+download+a+file

Hi, Olli. Thank you for your answer.

I tried to use the lazy download example, but didn’t get much succes with it.
My problem is that the FileDownloader cannot be created, because I don’t have the resource to download it yet. The resource to be downloaded will be generated when the user click on the button to export the components to PDF. Then, I can set the resource when it is generated.

The lazy example don’t go further to where i need to know how to implement it in my code.

Hi,

What you describe should be possible if you follow the first part of the tutorial:[code]
protected void init(VaadinRequest request) {
Button downloadButton = new Button(“Download image”);

StreamResource myResource = createResource();
FileDownloader fileDownloader = new FileDownloader(myResource);
fileDownloader.extend(downloadButton);

setContent(downloadButton);
}

private StreamResource createResource() {
return new StreamResource(new StreamSource() {
@Override
public InputStream getStream() {
// generate data here
}
}, “myImage.png”);
}
[/code]
The getStream() method of the StreamResource is called only when the download button is clicked, so you can dynamically generate the contents of the download at that point.