Blocking client side execution until server executes the service completely

54 views
Skip to first unread message

ankit

unread,
Jun 9, 2011, 2:13:11 AM6/9/11
to Google Web Toolkit
hii to all....im loading data from the server using asynchronous
callback. so is there any way that i can stop executing client side
execution until i get data from the server. any way to block
asynchronous behavior so that i can wait for the data from the
server....
this is the example....im using like.. and i dont want JVM to execute
further till recordSet is not populated..thanx for looking into
it..hope u will help me out

Service.loadData(mProcedureName, request, new AsyncCallback<Data>() {

public void onFailure(Throwable ex) {

Logger.getLogger(DataServiceImpl.class.getName()).error("Load data
failed.", ex);
}

public void onSuccess(Data data) {
recordSet.setRecords(data);
}
});
}

Paul Robinson

unread,
Jun 9, 2011, 3:33:41 AM6/9/11
to google-we...@googlegroups.com
It's really not a good idea to stop your user's browser from responding while you're making network calls. They will not thank you for it.

Your life with GWT will be *so* much easier if you just embrace asynchronous behaviour.

Paul

riyaz ahmed

unread,
Jun 9, 2011, 4:20:03 AM6/9/11
to google-we...@googlegroups.com
Hi paul,
 
I am facing a similar scenario,
If we go ahead with asynchronous call, how will we handle this scenario, how do we know when the data has been retrieved
 
Hi ankit,
 
Please let me know if you find a solution towards this
 
Thanks in advance
 
Riyaz

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




--
Riyaz
9916220381

Jens

unread,
Jun 9, 2011, 4:38:37 AM6/9/11
to google-we...@googlegroups.com
If you really need to wait then you have to put that code that needs to wait inside the onSuccess method (directly, via a method call or by sending an event).

Why do you have to wait? 

In most cases I have something like:

1.) disable controls
2.) make request
3.) re-enable controls once the request completes.

And if I have two requests where the second one depends on the first one I'll do them in a batch request that combines both requests into one.

-- J.

ankit

unread,
Jun 9, 2011, 5:11:43 AM6/9/11
to Google Web Toolkit
thnx Paul and Jens for ur replies..............actually my problem is,
there is client-server communication in my project. and data on the
server is fetched and populated into the model which is on client
side. due to asynchronous behavior and lack of multithreading, i am
not able to hold back execution till model is populated with the
fetched data from server. due to which my view is not able to populate
the data. hope u understand my problem. so i need some alternative of
multithreading so that i can hold the execution till i get response
from the server. Thnx for ur replies...

Jens

unread,
Jun 9, 2011, 5:53:11 AM6/9/11
to google-we...@googlegroups.com
I think you just have to get used to async programming. Its all about events and callbacks in GWT. Any kind of client server communication in GWT is async so there are no real alternatives that allows you to block execution. A web application lives from asynchronous communication. 

As said before you can only put your code inside the AsyncCallback's onSuccess method or send an event once everything is loaded from the server and let some instance react to that event in order to populate the view with the loaded data. That way the code that needs the data from the server will somehow "wait" but you won't block everything in your app.

Feel free to ask if you still have questions or post some more concrete code (you can also send me a direct mail if you do not want to expose your concrete code on that group). I think you just have to re-sturcture some of your code and everything will be fine.

-- J.

Paul Robinson

unread,
Jun 9, 2011, 6:45:02 AM6/9/11
to google-we...@googlegroups.com
For a good explanation on how asynchronous coding works, check out the great GWT beer example:
http://groups.google.com/group/google-web-toolkit/browse_frm/thread/faca1575f306ba0f/bd72c28afe5eb680

HTH
Paul

Ashton Thomas

unread,
Jun 9, 2011, 11:04:27 AM6/9/11
to Google Web Toolkit
Have to agree that you need to change your mindset and fully embrace
asynchronous (get used to events and callbacks:)

However, here is a good article on creating parallel async calls when
you can't do it in one call (for whatever reason)
http://www.summa-tech.com/blog/2010/11/29/parallel-asynchronous-calls-in-gwt/

GWT/The Web really pushes this whole async-ness (for a reason)


On Jun 9, 6:45 am, Paul Robinson <ukcue...@gmail.com> wrote:
> For a good explanation on how asynchronous coding works, check out the great GWT beer example:http://groups.google.com/group/google-web-toolkit/browse_frm/thread/f...
>
> HTH
> Paul

ankit

unread,
Jun 17, 2011, 6:01:32 AM6/17/11
to Google Web Toolkit
thnks 4 all ur replies...but my problem is combobox model is loading
data from the server and as u know GWT server connection is all
asynchronous ....so what should i do so that data must load on the
model before viewing on to the UI. is there any way i can halt the
execution or know that data has come from the Server.

On Jun 9, 8:04 pm, Ashton Thomas <ash...@acrinta.com> wrote:
> Have to agree that you need to change your mindset and fully embrace
> asynchronous (get used to events and callbacks:)
>
> However, here is a good article on creating parallel async calls when
> you can't do it in one call (for whatever reason)
>  http://www.summa-tech.com/blog/2010/11/29/parallel-asynchronous-calls...

Paul Robinson

unread,
Jun 17, 2011, 6:08:34 AM6/17/11
to google-we...@googlegroups.com
You still haven't embraced asynchronous behaviour.

(1) Display a message in the UI that says you're loading data
(2) Make the call to the server to ask for data
(3) In the callback, build whatever UI structures you require, and replace the "loading" message with the real thing

Paul

Jens

unread,
Jun 17, 2011, 6:23:05 AM6/17/11
to google-we...@googlegroups.com
See Pauls answer. In addition if you do not want to hide the combo box, just set a message to it and disable it. Then load you combo box data and when its done clear the combo box, fill in the data and re-enable it.

-- J.

ankit

unread,
Jul 4, 2011, 2:00:23 AM7/4/11
to Google Web Toolkit
Hey...Thanks 4 all ur replies....my problem is solved now....
Reply all
Reply to author
Forward
0 new messages