我的 GWT 应用程序没有运行 JSNI 调用的本机函数。有接受者吗?
我正在尝试在 GWT 应用程序中通过 JSNI 调用运行本机 Java 函数。它看起来像这样:
package foo.client;
public class AAA Implements EntryPoint, UIupdate {
public native void initChangeFunc() /*-{
$wnd.jsChangeView = function () {
[email protected]::changeToHistory();
alert("got here");
};
}-*/;
public void changeToHistory() {
Window.alert("Hello World");
//Change view here.
this.changeView("history");
this.changeHistoryView("bydate");
};
...
public void onModuleLoad() {
...
this.initChangeFunc();
}
}
将 jsChangeView() 函数调用附加到前端中的链接 onclick() 并单击它会导致“到达这里”警报,而不是“Hello World”警报,其他两个功能也没有运行。 GWT 不是我的专业领域,这也不是我的应用程序,所以我知道我在这里缺少一些基本的东西。有接受者吗?
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 () {
[email protected]::changeToHistory();
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?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
[电子邮件受保护]::changeToHistory()
仅引用方法(“函数指针”,如果你愿意的话,或者在 JavaScript 中,只是一个“函数”),它不会调用它。您必须编写[email protected]::changeToHistory() ()
来实际进行调用。当方法有参数时更明显,例如:
[电子邮件受保护]::changeToHistory(Ljava/lang/String;I)
与[电子邮件受保护]::changeToHistory(Ljava/lang/String;I)("foo", 3)
。[email protected]::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[email protected]::changeToHistory()()
to actually make the call.It's more obvious when the method has arguments, e.g.:
[email protected]::changeToHistory(Ljava/lang/String;I)
vs.[email protected]::changeToHistory(Ljava/lang/String;I)("foo", 3)
.