Export to GitHub

google-web-toolkit - issue #4898

Synchronized RPC requests


Posted on Apr 29, 2010 by Happy Horse

I know you say that sync-rpc is not needed, but i really need it for saving changes while leaving the page.

since if i trigger an RPC request from the onUnload event the user will get an error message when the RPC request has not finished before actually leaving the page.

with this patch you can do:

public interface I_DataServiceAsync { RequestBuilder save(Data data, AsyncCallback<Void> callback); }

RequestBuilder rb = GWT.create(I_DataService.class).save(data, yourAsyncCallback); ((I_HasSync)rb).setSync(true); try { rb.send(); } catch (RequestException ex) { onFailure(iex); }

to use/install: - put the files in a super source folder - move the I_HasSync.java file into your class path so you can use it et voila.

the best would be to have just an annotation for RPC methods, like @Sync(true) ;)

HTH

Attachments

Comment #1

Posted on May 2, 2010 by Happy Horse

this is the second (and last) version with annotations:

just do:

public interface I_DataServiceAsync { @SynchronizedRpcRequest void save(Data data, AsyncCallback callback); }

Attachments

Comment #2

Posted on May 3, 2010 by Swift Rhino

"""I know you say that sync-rpc is not needed, but i really need it for saving changes while leaving the page."""

May I object that you actually don't need sync calls, but rather need to rethink the way (and time) you save changes? If my laptop goes to sleep (or hibernate) mode, you won't get an unload event, but the session will probably be lost when I wake it up a few hours later. Same can go if I just don't use the "app" for a few hours, if the network goes down, etc. Browsers give you an (IMO) better solution: cancel the "on before unload" event ("window closing" in GWT parlance) so the user is given a chance to keep using the app (and save the changes itself before quiting). That's how GMail and Google Groups work when you leave without saving (GMail) or sending (GMail/Groups) your draft message, and that's waaay more reliable than issuing a sync RPC on "unload" (this is under discussion at the W3C and WHATWG what kind of "actions" should be allowed in "unload" event handling: prompts? http requests? assignment to document.location?)

Comment #3

Posted on May 3, 2010 by Happy Horse

well i have to say that i agree with you... i am doing my best to convince my boss ;)

Comment #4

Posted on May 17, 2010 by Happy Horse

for a more in depth discussion see: http://groups.google.com/group/google-web-toolkit/browse_thread/thread/79a31626bb32ca08/7d59eb49443645dd

Comment #5

Posted on Jul 13, 2010 by Grumpy Hippo

While the need is clear, adding this type of functionality would lead to a degraded UX (imagine the RPC taking an extended amount of time to return and the user not being able to close the tab/browser/etc.) In lieu of this, I would side with Thomas, suggesting that you pop up a dialog informing the user that they have unsaved data, and (if necessary, although I don't advocate this) continue popping this dialog up until you know the RPC has completed. Another alternative would be to save pending commits to local storage, and check for this data when your app loads again.

Comment #6

Posted on Dec 23, 2011 by Grumpy Dog

Issue 1631 has been merged into this issue.

Comment #7

Posted on Dec 23, 2011 by Grumpy Dog

(No comment was entered for this change.)

Comment #8

Posted on Mar 8, 2012 by Swift Rhino

Issue 7238 has been merged into this issue.

Status: Duplicate

Labels:
Category-RPC Type-Feature