GWT JSNI方法调用失败,但没有错误

时间:2012-11-09 23:57:23

标签: gwt mozilla jsni

我正在尝试在GWT应用程序中实现Mozilla的Persona。这是我设置为测试它的虚拟应用程序代码的一部分:

public class OpenId implements EntryPoint {

private native void callWatch(String email)
/*-{
    $wnd.navigator.id.watch({
        loggedInUser: email,
        onlogin: function(assertion){
            $wnd.alert("Calling method");
            this.@com.gallup.openid.client.OpenId::processLogin(Ljava/lang/String;)(assertion);
            $wnd.alert("Called Java Method");
        },
        onlogout: function(){alert("Logged Out!");}
    });
}-*/;

private void processLogin(String assertion){
    Window.alert("Logged in!");
    personaStatus.setText("Log In Complete.");
}
}

当我调用callWatch方法时,只显示“调用方法”警告框。其他任何一个都没有被召唤过。因此,由于某种原因,代码似乎在第一个警报下面的JSNI调用处停止。但是开发模式没有错误。

我不明白为什么不调用processLogin方法。

我以为我正确地关注了Google's Documentation

我确实尝试过写作

this.@com.gallup.openid.client.OpenId::processLogin(Ljava/lang/String;)(assertion);
由于this post

OpenID.@...instance.@...

我不确定还有什么可以尝试。

1 个答案:

答案 0 :(得分:4)

变量this指向紧邻它的函数,在本例中是您的onlogin JavaScript函数。您需要使用临时that变量(顺便说一下典型的JavaScript惯用语)

private native void callWatch(String email)
/*-{
  var that = this;
   ...
    onlogin: function(assertion){
      that.@com...

然后,理想情况下使用$entry(...),因此如果您注册了UncaughtExceptionHandler,您将看到错误消息。

另请参阅:https://stackoverflow.com/a/5235580/291741

相关问题