Community
Participate
Working Groups
Downloading files in RAP is not as easy as it could be for several reasons: - triggering a file download from Java respectively from JS is blocked by most Browsers for security reasons - RAP's navigation model must be taken into account to not accidently navigate away from the page (and lose the RAP session) A common approach suggested in the newsgroup is to use a Browser widget (IFrame) combined with a servlet/service handler. However, this requires some deeper insights in web technologies which are not necessary when programming with RAP in general. Therefore, providing a download widget out of the box would be a benefit for the platform. Patch will follow soon.
Created attachment 183890 [details] Download project with Demo class
Created attachment 185090 [details] Improved version Improvements: - abitrary content can be provided via a callback that returns an InputStream - extended demo to download resources from classpath - export packages - test case - naming conventions for package and bundle
I have an idea for another non-widget approach for downloading files in RAP. In my solution, I also provide the download-data via a ServiceHandler, but instead using a Widget that reads "Download" and requires user interaction I create a shell in the background that holds a single Browser widget (in the preWindowOpen() method). I call this shell the DownloadHook. I hide the shell as good as possible by setting the size to 0,0 and the alpha to 1 so it is invisible and should not be visible by the user. This is a Q&D solution for now, Actually I just need this seperate iFrame instance that is hidden. Now I can set the URL of this hidden Browser widget programmatically to the download url and the download dialog will open in the browser. This would make downloading files completely transparent to the user and the download can be initiated programmatically. This works in FF, Chrome and even IE. Although IE 8 disallows downloads by default and the user has to make an exception which causes the Browser to reload. It is also important to set the correct Content-Disposition so that the file is not opened in the hidden Browser frame with e.g. the PDF reader. The registration of the download servicehandler should also be transparent for the programmer. Since a download functionality is RAP-specific it could be provided by an extra plugin that does the servicehandler registration?! Maybe this mechanism could be provided along with the proposed download widget?! Just to give it some thoughts, what do you think? Greetings, Ben
(In reply to comment #3) > I have an idea for another non-widget approach for downloading files in RAP. > > In my solution, I also provide the download-data via a ServiceHandler, but > instead using a Widget that reads "Download" and requires user interaction I > create a shell in the background that holds a single Browser widget (in the > preWindowOpen() method). I call this shell the DownloadHook. I hide the shell > as good as possible by setting the size to 0,0 and the alpha to 1 so it is > invisible and should not be visible by the user. This is a Q&D solution for > now, Actually I just need this seperate iFrame instance that is hidden. > > Now I can set the URL of this hidden Browser widget programmatically to the > download url and the download dialog will open in the browser. This would make > downloading files completely transparent to the user and the download can be > initiated programmatically. > > This works in FF, Chrome and even IE. Although IE 8 disallows downloads by > default and the user has to make an exception which causes the Browser to > reload. > > It is also important to set the correct Content-Disposition so that the file is > not opened in the hidden Browser frame with e.g. the PDF reader. > > The registration of the download servicehandler should also be transparent for > the programmer. Since a download functionality is RAP-specific it could be > provided by an extra plugin that does the servicehandler registration?! Maybe > this mechanism could be provided along with the proposed download widget?! > > Just to give it some thoughts, what do you think? > > Greetings, > Ben We have used the exact same solution for a while. I think a similar idea may have been posted on the wiki. I posted our code to the newsgroup here: http://www.eclipse.org/forums/index.php?t=msg&goto=658804&S=c6a20a04e9f1c0b8e2f0ef5b1f46e815#msg_658804
The advantage to Stefan's approach as opposed to ours is that in our case IE blocks the download unless the user has configured it not to. When a file download is blocked IE pops up the yellow "information bar" at the top. If the user clicks that then the entire page is reloaded so they will likely lose their context. Some users may not be able to change that setting either. If an all-in-one widget is added to RAP, I would be in favor of Stefan's version for these reasons. Developers can still use the other approach if they know their users can work around this.