How to stall GWT app while it is writing file in background? Timer object??

41 views
Skip to first unread message

Joshua Carey

unread,
Feb 1, 2012, 1:52:52 PM2/1/12
to google-we...@googlegroups.com
I have a gwt application that calls a gwt servlet (from my presenter class) to write a PDF file to disk, then in my presenter class I display the newly created PDF using Window.open("my.pdf");.  The problem is that the window.open executes before the pdf is finished writing to disk.  I would like to know if there is a way to stall any further statements from occurring until the pdf is finished writing.  Or is there a way to use some sort of timer object that waits 5 seconds or more while the PDF is  being created?  It would be nice to prompt the user a message box that says "please wait while PDF is retrieved" and then when the PDF is finished writing, we could automatically close the message box and execute the window.open("my.pdf") command.  Here is the lines of code in the presenter class:

ButtonCell genericButtonCellType = new ButtonCell();
FieldUpdater<EOMDocument, String> previewUpdater = new FieldUpdater<EOMDocument, String>()
{
@Override
public void update(int index, EOMDocument object, String value)
{
if (object.getByteBlob() == null) {
Window.alert("Sorry but the PDF you are requesting from the database is empty. Please select another PDF to view!");
} else {
eventBus.writePdf(object.getByteBlob(), object.getIdocNumber());
        String blobURL =  GWT.getHostPageBaseURL() + "sp_pdf/" + object.getPreviewBlobPath();
        Window.open(blobURL, "Search And Preview - PDF Review", null);
}
}
};

Thanks for the help.

Joshua

Mark

unread,
Feb 1, 2012, 2:41:31 PM2/1/12
to Google Web Toolkit
The whole idea between AJAX is asynchronous operation, the client
continues working while the server does work. There's no telling how
long the server will take to do its work so a Timer is not the best
option. Since you want the client to react when the server finishes
you need to pass the workload to the server method and pass an
AsyncCallback object. In that object you put your Window.open() call
in the onSuccess() method.

Hope this helps.

Joshua Carey

unread,
Feb 1, 2012, 3:11:06 PM2/1/12
to google-we...@googlegroups.com
Actually, I have that exact setup now, the only difference is in my onSuccess method I really wasn't doing anything.  So in the client code I showed you above, I should take the logic regading the window.open and put it in the onSuccess method and that should avoid prematurely loading the window?  I think that solution is much, much better then my idea!!!  I'm gonna try that now.  Thanks a bunch.  :)


--
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-we...@googlegroups.com.
To unsubscribe from this group, send email to google-web-tool...@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/google-web-toolkit?hl=en.


Joshua Carey

unread,
Feb 1, 2012, 3:30:12 PM2/1/12
to google-we...@googlegroups.com
Hi Mark,

Your suggestion worked perfectly, except for one small thing.  For some reason moving the Window.open from the button click event, to the onSuccess method, now creates a "pop up" window, instead of a new tab..  Its weird because they are both being executed within the presenter class so i'm unsure why its doing that.  Also since its now making a popup instead of a new tab, google chrome setting need to be changed to allow popups.  Do you know why moving window.open would all of a sudden make a pop up instead of a new tab?

Thanks,

Joshua

On Wed, Feb 1, 2012 at 1:41 PM, Mark <mdsh...@gmail.com> wrote:
--
You received this message because you are subscribed to the Google Groups "Google Web Toolkit" group.

Thad

unread,
Feb 1, 2012, 4:51:35 PM2/1/12
to Google Web Toolkit
See http://groups.google.com/group/google-web-toolkit/browse_frm/thread/2bc7750aa72470f5/9afa4441d4fcceb0

In the 3rd message, I describe how I do something similar using a
hidden frame as my download target.
Reply all
Reply to author
Forward
0 new messages