[英]GWT call JS method from applet
Im trying to call a Javascript method from applet, i read some examples, but nothing works. 我试图从applet调用Javascript方法,我读了一些示例,但没有任何效果。
Applet : 小程序:
JSObject window = JSObject.getWindow(this);
String[] args = new String[]{"some string"};
window.call("alert2 ", args);
GWT, View GWT,视图
public static native void export() /*-{
$wnd.alert2 = function(result) {
@cl.covepa.client.main.shared.view.DlgVerificarHuellaView::alert2(Ljava/lang/String;)(result);
}
}-*/;
public static void alert2(String result) {
Dialogs.getInstance().alert("CONFIRMACION :" + result);
}
and at the constructor call, i test in onModuleLoad too. 在构造函数调用中,我也在onModuleLoad中进行测试。
export();
when the applet run, its say 小程序运行时,它会说
No such method "alert2 " on JavaScript object
JavaScript对象上没有这样的方法“ alert2”
its ok, i understand the code is obfuscated but i suppose this is the way for the method keep its name, but doesnt works, i still see this on client side 好的,我理解代码被混淆了,但是我想这是方法保留其名称的方法,但是不起作用,我仍然在客户端看到这一点
function dBb(){$wnd.alert2=function(a){T2c((!S2c&&(S2c=new X2c),S2c),'CONFIRMACION :'+a)}}
what i miss ?!, thanks 我想念什么?!,谢谢
UPDATE : 更新:
HTMLPanel contain a HTML object with this String, its add at show DialogBox. HTMLPanel包含一个带有此String的HTML对象,它在show DialogBox中添加。
<div>
<applet id="uploadApplet" code="app.VerifHuella.class"
archive="VerificarHuella.jar" width="322" height="465" MAYSCRIPT>
<param name="RUT" value="15645322"/>
</applet>
</div>
It seems your problem is that the method is not available in the window when you call it. 看来您的问题是调用该方法时该方法在窗口中不可用。 It could happen because three reasons:
之所以会发生,是因为三个原因:
export()
method in your onModuleLoad()
onModuleLoad()
调用export()
方法 Anyway, if you wanted to export classes and methods without using a single line of jsni you could try gwtexporter , in your case your code could look like: 无论如何,如果您想导出类和方法而不使用一行jsni,则可以尝试gwtexporter ,在您的情况下,您的代码应类似于:
class DlgVerificarHuellaView implements Exportable {
@Export($wnd.alert2)
public static void alert2(String msg) {
}
}
Another nice way to export a funcion without writing jsni is using gwtquery : 无需编写jsni即可导出功能的另一种好方法是使用gwtquery :
import static com.google.gwt.query.client.GQuery.*
Properties wnd = window.cast();
wnd.setFunction("alert2", new Function() {
public void f() {
Properties arg = getDataProperties();
DlgVerificarHuellaView.alert2(arg.get(0));
}
});
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.