Again, thanks for your tip. It got me going in the right direction.
For the record, my solution was to create (as Thomas suggested) a
"peer" callback object that extends JavaScriptObject that defined the
same method signature. So if my callback object was defined like
this:
public interface MyCallback {
void onSuccess(Object result);
}
I would defined the "peer" JSO like this:
public class MyCallbackJso extends JavaScriptObject {
protected MyCallbackJso() {
}
public final native void onSuccess(Object result) /*-{
this.onSuccess(result);
}-*/;
public static native MyCallbackJso wrap(MyCallback delegate) /*-{
var wrapped = { "delegate" : delegate };
wrapped.onSuccess = function(entity) {
this.delega...@mycallback::onSuccess(Ljava/lang/Object;)
(entity);
}
return wrapped;
}-*/;
}
And then wrap my calls to the service:
service.doSomethingAsync(MyCallbackJso.wrap(new MyCallback() {
public void onSuccess(Object result) {
//handle the result.
}
}));
-Ryan
On Feb 5, 9:21 am, Thomas Broyer <[email protected]> wrote:
> On Feb 4, 9:47 pm, Ryan Heaton <[email protected]> wrote:
>
> > Thanks for your reply. But I'm having trouble understanding your code.
>
> > The "publishGetStuff" method refers to $entry. What is that?
>
> It's a special function that wraps the function argument so that
> exceptions will be passed to your GWT.UncaughtExceptionHandler (if
> any)
>
> > The "staticGetStuff" method refers to a variable "service". Where is
> > that variable stored?
>
> It's your MyService instance, in this case probably a "private static
> MyService service".
>
> > It looks like when users call $wnd.getStuff then they have to pass in
> > a function, when I want them to pass in an object with a function
> > defined that matches the name of MyCallback.onSuccess method.
>
> Just change nativeGetStuff to call onSuccess.onSuccess(...) instead of
> onSuccess(...) (well, you'd probably rename the onSuccess argument to
> callback too...)
--
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.