On 16 juin, 17:08, samsus <[email protected]> wrote:
> Hi All,
>
> Im trying to use jsni to implement a interface (a callback) and use it
> as an argument in a function. here is what i have:
>
> -------------------------------------------------
>
>  package com.mypackage;
>
>  public interface MyCallback {
>
>       public void onResponseReceived(String text);
>
>  }
>
>  ------------------------------------------------
>
>  package com.mypackage;
>
>  public class MyClass {
>          public static String send(String text,MyCallback callback) {
>                  callback.onResponseReceived(text);
>                  return "";
>          }
>
>          private native void publish() /*-{
>              $wnd.send = @com.mypackage.MyClass::send(Ljava/lang/

It won't work; you should introduce a level of indirection:

public static String send(String text, JavaScriptObject callback) {
    callTheCallback(callback, text);
    return "";
}

private static native void callTheCallback(JavaScriptObject callback,
String text) /*-{
    callback(text);
}-*/;


...unless you provide some constructor for MyCallback that you can
pass "plain old JS functions" to be used by onResponseReceived
(onResponseReceived being implemented as a native method similar to
callTheCallback above).

> String;com/mypackage/MyCallback;);
>          }-*/;
>  }
>
> ------------------------------------------------
>
> im stuck, because "com/mypackage/MyCallback" is not considered a valid
> type,

Lcom/mypackage/MyCallback; would; you forgot the "L".


--~--~---------~--~----~------------~-------~--~----~
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
-~----------~----~----~----~------~----~------~--~---

Reply via email to