Put the println in your async callback (or in a function called from your async callback).
On Wed, Mar 18, 2009 at 11:31 PM, [email protected] <[email protected]>wrote: > > How do I wait for the response is completed in another class? > For example, I have a class called GetData > > public class GetData{ > private String query; > private String DEFAULT_URL = "http://localhost/book.php"; > String result = new String(); > > public GetData(String query) { > this.query = query; > this.search(); > } > > private void search() { > String url = URL.encode(DEFAULT_URL + "?query=" + > this.query); > RequestBuilder builder = new > RequestBuilder(RequestBuilder.GET, > url); > builder.setCallback(new RequestCallback() { > public void onError(Request request, Throwable > exception) { > } > public void onResponseReceived(Request request, > Response response) > { > if (Response.SC_OK == > response.getStatusCode()) { > result = response.getText(); > } > } > }); > > try { > builder.send(); > } catch (RequestException e) { > } > } > > public String getResult(){ > return this.result; > } > } > > So, when I call > > GetData test = new GetData(query); > System.out.println(test.getResult()); > > will return nothing. But I'm sure that it will return something. > The problem is System.out.println(test.getResult()); is executed > before the result=response.getText(); > How can I fix that? > > John > > > > --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Google Web Toolkit" group. To post to this group, send email to [email protected] To unsubscribe from this group, send email to [email protected] For more options, visit this group at http://groups.google.com/group/Google-Web-Toolkit?hl=en -~----------~----~----~----~------~----~------~--~---
