> 1) Check if user is logged in
> 2) Get Some data List list1 e.g. getUserAddresses
> 3) Get some data List list2 e.g. getUserFriends
> 4) Get Some data List List3 e.g. getUserCommunities
> 5) now create the UI based on above data retrieved. Now as all GWT RPC
> calls are asynchronous, so at the step 5 i am not sure whether all
> the calls(1,2,3,4) have completed by the time i reached at step 5, and
> there is no Thread object in GWT so i can not wait or join till all
> call completes.
> And writing such code can be pain.(e.g. writing a Asyncallback for
> step 1 then if it success then call step 2 and write asyncallback 2
> and in its successs function call step 3 and so on)
Do the UI-update in a method called updateUI where you check if all
necessary data (e.g. above lists) are present and call this method
in every onSuccess-method of the different AsyncCallback-classes.
Regards, Lothar
The way I have addressed some of the problems you mention is with an
event-based model. For example, to display the results of
getUserAddresses(), I might have a ListBox widget backed by a model of
some sort. The list and model are tied together with event listeners
such that clicking in the UI updates the model and changes in the
model (adding and removing addresses, say) are reflected in the UI.
In such a setup, the completion of an RPC will eventually trigger a
model event that causes the list to redraw itself. Working this way
solves a lot of problems because most of my code is decoupled from the
RPC details and I don't have to worry about RPC being synchronous or
asynchronous.
Ian
> Do you see any problem in having synchronous calls.? except that it
> may hang the UI for a second and that is acceptable.
If the server is not available or the request get lost for some
other reason, the UI of the browser hangs for a couple of minutes
and not seconds.
Regards, Lothar
In the case of waiting for a couple of seconds, depending on the
browser and version, you cannot change tabs, cannot close the browser
or anything. This is a VERY NAUGHTY thing to do intentionally.
In the case of a network failure this frozen state lasts indefinitely,
and that sort of thing really pisses off your users. particularly if
the only way they an figure out how to exit your web app is to reboot
their computer!
Learn to divide up your application into the things that need to
happen before the RPC is sent, and the things that happen after. place
those things in their own methods, then call the "after" methods from
your Callback. Your users will thank you for it later.
-jason
Lothar's original suggestion
is the way to go.
"Do the UI-update in a method called updateUI where you check if all
necessary data (e.g. above lists) are present and call this method
in every onSuccess-method of the different AsyncCallback-classes. "