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);
}
}-*/;
这将在 FireBug 控制台中抛出一个 java.lang.ClassCastException
,尽管 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屋!
查看全文