帮助通过 JSNI 调用传递复杂对象以绕过静态范围
所以我有一个 GWT 应用程序,我试图调用一个函数来从外部按钮更改应用程序的视图。通常这被称为“this.internalFunction('string')”。问题是 JSNI 通过静态方法工作,因此有问题的对象丢失了。解决方案:将应用程序的对象本身传递给 JSNI 调用,并从那里调用该对象的函数调用!解决方案的问题:这不起作用。 :(
类看起来像这样:
package blah.package;
public class Foo implements A, B {
public native void initChangeFunc() /*-{
$wnd.jsChangeView = $entry([email protected]::doSomething
(Lblah.package.Foo;)(this));
//Pass this to the function call to do calls on app object
}-*/;
public void doSomething(Foo obj) {
//Change view here.
obj.internalFunction("parameter");
};
public void internalFunction(String param) {
//Do stuff with param.
}
}
在模块加载时,调用 initChangeFunc() 并访问页面本身上的 jsChangeView() 。
编译错误表明编译器找不到 blah.package.Foo,这是因为我的参数类型签名 ( Lblah.package.Foo 部分)是错误的。
[ERROR] Line 64: Expected a valid parameter type signature in JSNI method reference
So I've got a GWT app and I'm trying to invoke a function to change the app's view from an outside button. Normally this is called with as "this.internalFunction('string')". The problem is that JSNI works via static methods and so the object in question is lost. The solution: pass the app's object itself to the JSNI call and invoke that object's function calls from there! The problem to the solution: this doesn't work. :(
Class looks something like this:
package blah.package;
public class Foo implements A, B {
public native void initChangeFunc() /*-{
$wnd.jsChangeView = $entry([email protected]::doSomething
(Lblah.package.Foo;)(this));
//Pass this to the function call to do calls on app object
}-*/;
public void doSomething(Foo obj) {
//Change view here.
obj.internalFunction("parameter");
};
public void internalFunction(String param) {
//Do stuff with param.
}
}
On module load, call initChangeFunc() and access jsChangeView() on the page itself.
Compile errors suggest that the compiler can't find blah.package.Foo, and that's because my parameter type signature (the Lblah.package.Foo part) is wrong.
[ERROR] Line 64: Expected a valid parameter type signature in JSNI method reference
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
首先,尽量不要破坏调用
Foo::doSomething
的行,并检查它是否有帮助。First thing's first, try not to break the line calling
Foo::doSomething
, and check to see if it helps.