Hi,
i have some trouble with opening a StreamResource. In the past, i was just using getApplication().getMainWindow().open(myStreamResource) after hitting a button on which the myStreamResource was generated.
However, just now, i’ve implemented a progress bar to indicate to the user how long it is going to take to generate the myStreamResource. So i start 2 new threads when hitting the ‘download’ button in my Vaadin app; 1 thread that updates the progress bar and 1 that generates the myStreamResource. This last thread then also invokes the getApplication().getMainWindow().open(myStreamResource) method.
This gives issues with Vaadin as i see the red ‘Communication Problem’ message when the myStreamResource is ready to download. I’m able to download the content, and after clicking ‘continue’ on the Communication Problem dialog, the GUI continues, but it is annoying for the user.
Apparently this happens because i open the StreamResource in the same window and that window is being painted at that moment because of the progress bar.
So what i tried, is using getApplication().getMainWindow().open(myStreamResource,“_blank”). This runs without problem on Firefox and Chrome, but in Internet Explorer, it gives me a very quick popup which then disappears immediately without giving the possibility to download the content.
Any suggestion on how i could fix this for IE?
p.s. Some more information on what the myStreamResource contains:
myStreamResource is an object of the following class:
public class DownloadResource extends StreamResource {
private final String filename;
public DownloadResource(File fileToDownload, Application application)
throws FileNotFoundException {
super(new FileStreamResource(fileToDownload), fileToDownload.getName(),
application);
this.filename = fileToDownload.getName();
this.setCacheTime(5 * 1000);
this.setMIMEType("application/octet-stream");
}
@Override
public DownloadStream getStream() {
DownloadStream stream = new DownloadStream(getStreamSource()
.getStream(), "application/octet-stream", filename);
stream.setParameter("Content-Disposition", "attachment; filename=\""
+ filename + "\"");
return stream;
}
private static class FileStreamResource implements
StreamResource.StreamSource {
private final InputStream inputStream;
public FileStreamResource(File fileToDownload)
throws FileNotFoundException {
inputStream = new FileInputStream(fileToDownload);
}
@Override
public InputStream getStream() {
return inputStream;
}
}
}