GWT JSNI - 传递字符串的问题 [英] GWT JSNI - problem passing Strings
本文介绍了GWT JSNI - 传递字符串的问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我试图在我的GWT项目中提供一些函数钩子:
I'm trying to provide some function hooks in my GWT project:
private TextBox hello = new TextBox();
private void helloMethod(String from) { hello.setText(from); }
private native void publish() /*-{
$wnd.setText = $entry(this.@com.example.my.Class::helloMethod(Ljava/lang/String;));
}-*/;
publish()
在 onModuleLoad()
。但是这不起作用,对于在控制台中为什么没有提供反馈。我也试过:
publish()
being called in onModuleLoad()
. But this doesn't work, providing no feedback as to why in the dev console. I've also tried:
private native void publish() /*-{
$wnd.setText = function(from) {
alert(from);
this.@com.example.my.Class::helloMethod(Ljava/lang/String;)(from);
}
}-*/;
这会折腾 java.lang.ClassCastException
在FireBug控制台中,虽然 alert
会触发很好。建议?
which will toss a java.lang.ClassCastException
in the FireBug console, though the alert
fires just fine. Suggestions?
推荐答案
private native void publish(EntryPoint p) /*-{
$wnd.setText = function(from) {
alert(from);
p.@com.example.my.Class::helloMethod(Ljava/lang/String;)(from);
}
}-*/;
您可以试试这段代码吗?
Could you give this code a try?
这篇关于GWT JSNI - 传递字符串的问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文