Zip download without Window.open()

88 views
Skip to first unread message

Sean

unread,
Jul 27, 2011, 8:07:58 AM7/27/11
to google-we...@googlegroups.com
Hi, 

I've followed a bunch of tutorials and I'm able to click a button, send parameters via a Window.open() call to an HttpServlet and it will construct a bunch of files, zip them up and send them back. The problem is sometimes creating these files can take some time, and a blank window just stares at me while it's doing so. I was wondering if there's a nicer way, like an RPC so I can tell when it's returned or an error has occurred but still have a File Dialog pop up for the user to save the .zip as normal? 

Thank you.

jhulford

unread,
Jul 27, 2011, 10:21:53 AM7/27/11
to Google Web Toolkit
We show a "wait" dialog, then send an RPC telling the server to kick
off a backend process (ie. zip up the files), the RPC returns an
identifier (a UUID) to the caller, the caller then polls every so
often sending that UUID to identify which service it's asking about to
get an update on whether the backend process is done or not. When the
polling call indicates the process is done, the client initiates the
download by calling a download servlet directly.

Thad

unread,
Jul 27, 2011, 12:50:27 PM7/27/11
to Google Web Toolkit
While the RPC preps the file(s), I put up a "wait" dialog.

The download is done with a servlet which I direct to a hidden frame.
In my project's HTML I put

<iframe src="javascript:''" id="__gwt_downloadFrame" style="width:
0;height:0;border:0"></iframe>

just below my history frame. In loading my module class is

private static final String DOWNLOAD_IFRAME = "__gwt_downloadFrame";
private static Frame downloadFrame;

which I wrap in onModule load with

// Get the hidden frame that's our download target.
downloadFrame =
Frame.wrap(Document.get().getElementById(DOWNLOAD_IFRAME));

and make available with a static method:

public static void downloadURL(String url) {
downloadFrame.setUrl(url);
}

If the RPC completes properly, I call the download servlet:

String saveURL = GWT.getModuleBaseURL() +
"downloadServlet?..." [params]
MyProject.downloadURL(saveURL);

You may have to do some other hand waving in the servlet to set the
proper headers, esp.with SSL (http://www.jspwiki.org/wiki/
BugSSLAndIENoCacheBug).

On Jul 27, 8:07 am, Sean <slough...@gmail.com> wrote:

Sean

unread,
Jul 27, 2011, 3:08:00 PM7/27/11
to google-we...@googlegroups.com
Thank you for the ideas guys! I will try to implement something like that!
Reply all
Reply to author
Forward
0 new messages