Here's some code. Perhaps this or a modification should be included in
gwt itself.

There are a few problems with downloading files.

1) IE doesn't always let you open a file download dialog. It will on
some machines, others it won't.
2) Users double click. Prevent this!
3) When opening a window from javascript you want to test whether the
window has been blocked.

You'll have to adjust the code below as it's got some things specific
to our codebase, but it gives you the general idea.

public void download(String title, ClientFile file){
                if (Browser.isInternetExplorer()) {
                        new FileResultsDialog("Download", file).show();
                        return;
                }

                if (!PopupDetectingWindow.open(file.getURL(), "_blank", "")) {
                        // show HUGE pop-up blocked message.
                        controller
                                        .getCurrentPage()
                                        .showErrorMessage(
                                                        "Your download was 
blocked! Please enable popups for this site.
This is usually done in a small toolbar just above this sites window.
To test, just click download again.");
                }


public class PopupDetectingWindow {

        /**
         * Opens a new browser window. The "name" and "features" arguments
are
         * specified <a href=
         * 'http://developer.mozilla.org/en/docs/DOM:window.open'>here</a>.
         *
         * @param url
         *            the URL that the new window will display
         * @param name
         *            the name of the window (e.g. "_blank")
         * @param features
         *            the features to be enabled/disabled on this window
         * @return whether or not the popup was opened
         */
        public static native boolean open(String url, String name, String
features) /*-{
            var mine = $wnd.open(url, name, features);
            if( mine ) return true;
            return false;
          }-*/;
}


in our file results dialog (just a popuppanel):

ExternalHyperlink externalHyperlink = new
ExternalHyperlink(file.getName(), file.getURL());
headerPanel.addLink(externalHyperlink);

Hope that helps!

On Feb 19, 4:15 pm, Geoffrey Wiseman <geoffrey.wise...@gmail.com>
wrote:
> I have a GWT application that uses GWT-RPC to send data back and forth
> to the server.  I've got a button that downloads a PDF based on that
> data from the server.  PDF Generation works fine, and the download
> worked fine using Window.open().
>
> However, as it stood, the download would not include any data that had
> been changed on-screen; but if I add a GWT-RPC call before the
> download, then IE7 blocks the download because it decides that the
> download is not the direct result of user action (I guess because the
> Window.open happens after the async 'save my data' call).
>
> I've tried some other suggestions in the group's archive for iframes
> and the like, but all of these are also blocked by the download
> blocker.  Has anyone run into this and found a solution that they're
> happy with?  Sadly, IE7 is the target browser for this client, so it's
> a bit of an issue for me.

-- 
You received this message because you are subscribed to the Google Groups 
"Google Web Toolkit" group.
To post to this group, send email to google-web-tool...@googlegroups.com.
To unsubscribe from this group, send email to 
google-web-toolkit+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/google-web-toolkit?hl=en.

Reply via email to