Download a resource from current window

Hi,

I have some portion of code which downloads an ExternalResource from my window :

getWindow().open(new ExternalResource("myHTTPlink"));

Problem is : The application closes and session expires when the resource is downloaded.

Then I took a look at the javadoc :

Question is : what if I want to download my external resource without opening a new Window ?

Thanks

Hi,

I had the same problem. I solved it with a hidden Embedded and overriding the resource MIME type to return “application/octect-stream”:

Layout stuff:

    Embedded downloader = new Embedded();
    downloader.setType(Embedded.TYPE_BROWSER);
    downloader.setWidth("0px");
    downloader.setHeight("0px");
    layout.addComponent(downloader);

Resource stuff:


FileResource fr = new FileResource(myFile, getApplication()){
	@Override
	public String getMIMEType(){
		return "application/octect-stream";
	}
};
downloader.setSource(fr);

You can do this with any Resource type. You only have to override getMIMEType() method to return “application/octect-stream”. Otherwise file contents may be rendered into the embedded’s iframe.

I think this works because the main window location object never changes and close events are never fired to the server.

Sorry for my english, I hope I was clear.

Regards,

-Germán