Async RPC during CloseHandler.onClose() cancelled?

45 views
Skip to first unread message

Danny Goovaerts

unread,
Apr 16, 2010, 11:44:47 AM4/16/10
to Google Web Toolkit
In the application that I'm building I've implemented a
CloseHandler.onClose() which saves the local state in the database at
the server side. This state is reloaded automatically when you log on
the next time (fromthe same browser or from another browser, that's
why I am not storing it in a cookie in the client).

This all works as expected when you close the browser (or the browser
tab) or when you navigate to another url.
The application is supported in multiple languages . I switch language
by replacing the URL by a new URL with locale query parameter (for
example, the URL for the default language is http://www.mysite.eu/ ,
the URL for the french version is http://www.mysite.eu/?locale=fr).
This causes a reload and the application is reinitialized in the new
locale.

However in this case, the async call in the CloseHandler.onClose()
method apparently is not called or it is called, but it is cancelled.
I'm convinved that it is called but it is cancelled as a result of a
timing issue.
I've done the following tests:
* in web mode, the problem occurs
* in web mode, when I have emptied the browser cache, the problem does
not occur
* in hosted mode when I step through it in the debugger, the
CloseHandler.onClose() method is called and the RPC succeeds
* in hosted mode, not in the debugger, the RPC succeeds
* I've also tried moving the RPC call in a Window.closingHandler where
I set a message in the ClosingEvent. This causes a popup window. In
this case, the RPC call also succeeds

This leads me to the conclusion that in in Web mode, the reload
happens fast when the HTML page and the java script are cached, and
that this causes the RPCto be canceled.

What do you think?

Is there a way to prevent the RPC call from being cancelled?

Thanks in advance,

Danny

--
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.

Thomas Broyer

unread,
Apr 16, 2010, 12:12:53 PM4/16/10
to Google Web Toolkit


On Apr 16, 5:44 pm, Danny Goovaerts <danny.goovae...@gmail.com> wrote:
> In the application that I'm building  I've implemented a
> CloseHandler.onClose() which saves the local state in the database at
> the server side. This state is reloaded automatically when you log on
> the next time (fromthe same browser or from another browser, that's
> why I am not storing it in a cookie in the client).
>
> This all works as expected when you close the browser (or the browser
> tab) or when you navigate to another url.
> The application is supported in multiple languages . I switch language
> by replacing the URL by a new URL with locale query parameter (for
> example, the URL for the default language ishttp://www.mysite.eu/,
> the URL for the french version ishttp://www.mysite.eu/?locale=fr).
> This causes a reload and the application is reinitialized in the new
> locale.
>
> However in this case, the async call in the CloseHandler.onClose()
> method apparently is not called or it is called, but it is cancelled.
> I'm convinved that it is called but it is cancelled as a result of a
> timing issue.
> I've done the following tests:
> * in web mode, the problem occurs
> * in web mode, when I have emptied the browser cache, the problem does
> not occur
> * in hosted mode when I step through it in the debugger, the
> CloseHandler.onClose() method is called and the RPC succeeds
> * in hosted mode, not in the debugger, the RPC succeeds
> * I've also tried moving the RPC call in a Window.closingHandler where
> I set a message in the ClosingEvent. This causes a popup window. In
> this case, the RPC call also succeeds
>
> This leads me to the conclusion that in in Web mode, the reload
> happens fast when the HTML page and the java script are cached, and
> that this causes the RPCto be canceled.
>
> What do you think?
>
> Is there a way to prevent the RPC call from being cancelled?

Using onClose to save things is unreliable and risky (you'd better
have an explicit "save" button and in case you have unsaved changes
ask the user to save them before "closing", using a ClosingHandler).

In the case where you reload the app (with a slightly different URL),
why not doing the RPC and do the reload in the onSuccess? (and because
you have no unsaved changes, you don't need to save again in the
onClose, or warn/ask the user in the ClosingHandler)

Danny Goovaerts

unread,
Apr 17, 2010, 3:50:36 AM4/17/10
to Google Web Toolkit
Moving the reload to the onSuccess is a good suggestion.
Thanks!
Reply all
Reply to author
Forward
0 new messages