Ignoring requestFactory responses on page reload

83 views
Skip to first unread message

Samin Pour

unread,
Jun 12, 2014, 3:22:46 AM6/12/14
to google-we...@googlegroups.com
 Hi Everyone

My question might be very basic but couldn't find the answer anywhere.

I'm working with requestFactory and send some requests to the server at almost the same time. One of these request takes couple of seconds, if the user refresh the page before the  response is ready,  obviously the onFailure() method of the "Receiver" class will be called to catch the Error (the message is just "Server Error 0") and therefore throw an Exception into user's face.

Now this my question, can I ask the receiver not to wait for the response anymore? Or is there a way to check for all the awaiting receivers and tell them to ignore all incoming responses? I know I can ignore the "ServerFailure" on the OnFailure() method or just log it, but then I can't distinguish between a page refresh or real server malfunction.

Any ideas? Would be happy if somebody can help  :)

Cheers
Samin


Alberto Mancini

unread,
Jun 13, 2014, 8:31:25 AM6/13/14
to google-we...@googlegroups.com
to inform the user that should wait until the response is ready.
I think it is at least less dangerous than ignoring eventual errors.

Alberto.








--
You received this message because you are subscribed to the Google Groups "Google Web Toolkit" group.
To unsubscribe from this group and stop receiving emails from it, send an email to google-web-tool...@googlegroups.com.
To post to this group, send email to google-we...@googlegroups.com.
Visit this group at http://groups.google.com/group/google-web-toolkit.
For more options, visit https://groups.google.com/d/optout.

Samin Pour

unread,
Jun 17, 2014, 1:10:05 AM6/17/14
to google-we...@googlegroups.com
Thanks Alberto :)

Isn't this handler triggered for closing the Window? I'm just refreshing a page which doesn't fire the associated event. Or am I missing something?

Thanks again
Samin

Alberto Mancini

unread,
Jun 17, 2014, 3:04:50 AM6/17/14
to google-we...@googlegroups.com
Hi Samir,
the page refresh should call the closinghandler cause a refresh is a page unload followed by a load and the closing handler essentially
is a listener to 'onbeforeunload' event.

Cheers,
   Alberto

Note:
there are issues with the returned message so if you go for a closing handler read this also:






Samin Pour

unread,
Jun 19, 2014, 2:40:14 AM6/19/14
to google-we...@googlegroups.com
Hi Alberto,

Thanks for your tip :) Unfortunately I can't inform the user to wait (I mean the product description is to let the user to do what ever they want without disturbing them) So I need to find the way to let the Receiver class not to wait for the response.

Any ideas?

Thanks again
Samin


On Tuesday, June 17, 2014 5:04:50 PM UTC+10, Alberto Mancini wrote:
Hi Samir,
the page refresh should call the closinghandler cause a refresh is a page unload followed by a load and the closing handler essentially
is a listener to 'onbeforeunload' event.

Cheers,
   Alberto

Note:
there are issues with the returned message so if you go for a closing handler read this also:




On Tue, Jun 17, 2014 at 7:10 AM, Samin Pour <sam...@gmail.com> wrote:
Thanks Alberto :)

Isn't this handler triggered for closing the Window? I'm just refreshing a page which doesn't fire the associated event. Or am I missing something?

Thanks again
Samin


On Friday, June 13, 2014 10:31:25 PM UTC+10, Alberto Mancini wrote:
to inform the user that should wait until the response is ready.
I think it is at least less dangerous than ignoring eventual errors.

Alberto.





--
You received this message because you are subscribed to the Google Groups "Google Web Toolkit" group.
To unsubscribe from this group and stop receiving emails from it, send an email to google-web-toolkit+unsub...@googlegroups.com.

Thomas Broyer

unread,
Jun 19, 2014, 7:01:21 AM6/19/14
to google-we...@googlegroups.com
If you go to http://jsfiddle.net/vX8uK/ you'll see that you'll have an onbeforeunload event (in GWT, Window.ClosingEvent) before the request is abort with status=0, and then you have the onunload (in GWT, CloseEvent).
That means you can listen to Window.ClosingEvent and set a flag to ignore subsequent errors. In case you have a prompt in Window.ClosingEvent added by other means (e.g. Places & Activities), then you'll have to handle the case where the user canceled the navigation and unset your flag; you can do that, for example, by resetting the flag in case of successful response, and/or listen to some mouse or keyboard events.
To centralize the flag processing, use a custom RequestTransport extending the DefaultRequestTransport and wrapping the RequestCallback to deal with the responses (at the RequestBuilder level, before they're transformed to RequestFactory's Receiver calls)

Samin Pour

unread,
Jun 23, 2014, 2:31:13 AM6/23/14
to google-we...@googlegroups.com
Thomas,

Thank you for the detailed answer (as always) :)

Cheers
Samin
Reply all
Reply to author
Forward
0 new messages