Problem with RPC

3 views
Skip to first unread message

rapsli

unread,
Mar 9, 2007, 10:51:45 AM3/9/07
to Google Web Toolkit
Hello

Following code snipped:

public String[] getCompletionItems(String str){
System.out.println("Zeile 26");

AsyncCallback callback = new AsyncCallback() {
public void onSuccess (Object result)
{
System.out.println("Zeile 30");
s = (String[])result;
}

public void onFailure (Throwable ex)
{
//RootPanel.get().add(new HTML(ex.toString()));
RootPanel.get("autocomp").add(new HTML(ex.toString()));
}
};
async.getAutocompletion(str, callback);
System.out.println("Zeile 41");
return s;
}

Output:
Zeile 26
Zeile 41
Zeile 30

So for the return value I always get the value from the last call of
the method. How can I assure, that the RPC method is called and answer
is waited for? I hope someone has a some good advice.

rapsli

Ian Petersen

unread,
Mar 9, 2007, 10:59:52 AM3/9/07
to Google-We...@googlegroups.com
> How can I assure, that the RPC method is called and answer
> is waited for?

You can't. GWT's RPC mechanism is _asynchronous_. You set up the
call with an associated handler, and then you issue the call. When
the browser is done receiving the response it will eventually get
around to calling your handler. You have no control over when that
will be, but you can be sure it'll be sometime "in the future" and it
will happen after the function that issues the call has returned.

Ian

--
Tired of pop-ups, security holes, and spyware?
Try Firefox: http://www.getfirefox.com

dgirard

unread,
Mar 9, 2007, 4:27:36 PM3/9/07
to Google Web Toolkit
I think you can put a transparent div just before the asynchronous
call. This div will catch all the event from the user.
You remove the div on success or failure.
Didier

dgirard

unread,
Mar 9, 2007, 4:50:43 PM3/9/07
to Google Web Toolkit
I have just done it with a transparent image, it works perfectly :


button.addClickListener(new ClickListener() {
public void onClick(Widget sender) {

image.setVisible(true);

TestSynchronousAsync testSynchronous =
TestSynchronous.Util.getInstance();
AsyncCallback asyncCallback = new AsyncCallback(){

public void onFailure(Throwable caught) {
image.setVisible(false);

}

public void onSuccess(Object result) {
image.setVisible(false);

}};
testSynchronous.sayHello(asyncCallback);
}});

rapsli

unread,
Mar 10, 2007, 1:37:20 AM3/10/07
to Google Web Toolkit
Hello
Thanks for the replies. It helped a lot and could have saved me a
couple of hours if I had know earlier...

Rapsli

> > > rapsli- Zitierten Text ausblenden -
>
> - Zitierten Text anzeigen -

Reply all
Reply to author
Forward
0 new messages