views:

207

answers:

2

My program has essentially 3 steps: 1) Query Geocoder object for some Coordinates and store them in a Collection 2) Send the results to my main module for plotting on a map 3) Plot them on a google map widget

I have created a Requestor class for the purpose of handling the Geocoding -- this class has a getResults() function that returns an ArrayList of coordinates to my main module to be plotted on the map.
However, when I try to do all 3 steps within the confines of my onModuleLoad() method, I run into a concurrency problem and pull null results from the result set. I have gotten this working with a set of 3 buttons (request, pull results, and plot) but would like to have them fired automatically when the module loads.
I suspect this has something to do with firing Events and having Handlers in the proper places; if that is the case please provide a concrete example as I have tried to find a good tutorial on EventHandlers with some difficulty.

A: 

I've fixed the problem using a Timer and a 5000 ms schedule.

I don't do GWT, so I can't go in depth, but after all it look like that you're (or it's) using separate threads to do the processing. If this is true, then you basically need to (let it) join the thread(s) before doing something with their final result(s).

BalusC
+1  A: 

It sounds that the Requestor class is called asynchronously. In that case you can use EventBus (implemented using HandlerManager - GWT 1.6 or later) to send and subscribe to events within GWT. Thus, upon getting result from geocoding service you can send an event with the results. The module expecting results subscribes to this event with EventBus.

You may want to check out gwt-presenter and gwt-dispatch applications for implementation and examples.

grigory