开发者

My GWT app isn't running a native function off of a JSNI call. Any takers?

I'm attempting to run a native Java function off of a JSNI call in my GWT app. It looks something like this:

package foo.client;

public class AAA implements EntryPoint, UIupdate {

public native void initChangeFunc() /*-{
    $wnd.jsChangeView = function () {

        this.@foo.client.AAA::changeToHistory();开发者_StackOverflow中文版
        alert("got here");
    };
}-*/;
public void changeToHistory() {
    Window.alert("Hello World");
    //Change view here.
    this.changeView("history");
    this.changeHistoryView("bydate");
};

...

public void onModuleLoad() {

...

    this.initChangeFunc();
}

}

Attaching the jsChangeView() function call to a link onclick() in the front-end and clicking it results in a "got here" alert, but not a "Hello World" alert, and the other two functions aren't running either. GWT isn't my area of expertise, and this isn't my app, so I know I'm missing something basic here. Any takers?


this.@foo.client.AAA::changeToHistory() is only referencing the method (a "function pointer" if you like, or, in JavaScript, just a "function"), it doesn't call it. You have to write this.@foo.client.AAA::changeToHistory()() to actually make the call.

It's more obvious when the method has arguments, e.g.: this.@foo.client.AAA::changeToHistory(Ljava/lang/String;I) vs. this.@foo.client.AAA::changeToHistory(Ljava/lang/String;I)("foo", 3).

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜