2010-11-04 92 views
4

我有一个GWT应用程序,包括一个嵌入的小程序。GWT JSNI:调用applet方法?

我想用JNSI让GWT按钮将数据推到小程序,但在那一刻我甚至无法得到它连接。寻找一些帮助 - 似乎无法找到解决如何进行交谈的任何事情。

在我的入口点I类定义:

native void doSomething() /*-{ 
    $doc.applet_id.doSomething(); 
}-*/; 

这一点我通过函数clickhandler钩到一个按钮。在该applet主类,有一个doSomething()方法,并在页面我通过启动小程序:

<script> 
    var attributes = {codebase:'http://localhost:8888/', 
        code:'Applet.class', archive:'applet_test.jar', id:'applet_id', 
        width:100, height:40} ; 
    var parameters = {fontSize:16, jnlp_href:'launcher.jnlp'} ; 
    var version = '1.6' ; 
    deployJava.runApplet(attributes, parameters, version); 
</script> 

堆栈跟踪为

com.google.gwt.event.shared.UmbrellaException: One or more exceptions caught, see full set in UmbrellaException#getCauses 
    at com.google.gwt.event.shared.SimpleEventBus.doFire(SimpleEventBus.java:214) 
    at com.google.gwt.event.shared.SimpleEventBus.fireEvent(SimpleEventBus.java:103) 
    at com.google.gwt.event.shared.HandlerManager.fireEvent(HandlerManager.java:96) 
    at com.google.gwt.user.client.ui.Widget.fireEvent(Widget.java:107) 
    at com.google.gwt.event.dom.client.DomEvent.fireNativeEvent(DomEvent.java:116) 
    at com.google.gwt.user.client.ui.Widget.onBrowserEvent(Widget.java:155) 
    at com.google.gwt.user.client.DOM.dispatchEventImpl(DOM.java:1308) 
    at com.google.gwt.user.client.DOM.dispatchEvent(DOM.java:1264) 
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) 
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39) 
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25) 
    at java.lang.reflect.Method.invoke(Method.java:597) 
    at com.google.gwt.dev.shell.MethodAdaptor.invoke(MethodAdaptor.java:103) 
    at com.google.gwt.dev.shell.MethodDispatch.invoke(MethodDispatch.java:71) 
    at com.google.gwt.dev.shell.OophmSessionHandler.invoke(OophmSessionHandler.java:157) 
    at com.google.gwt.dev.shell.BrowserChannelServer.reactToMessagesWhileWaitingForReturn(BrowserChannelServer.java:326) 
    at com.google.gwt.dev.shell.BrowserChannelServer.invokeJavascript(BrowserChannelServer.java:207) 
    at com.google.gwt.dev.shell.ModuleSpaceOOPHM.doInvoke(ModuleSpaceOOPHM.java:126) 
    at com.google.gwt.dev.shell.ModuleSpace.invokeNative(ModuleSpace.java:561) 
    at com.google.gwt.dev.shell.ModuleSpace.invokeNativeObject(ModuleSpace.java:269) 
    at com.google.gwt.dev.shell.JavaScriptHost.invokeNativeObject(JavaScriptHost.java:91) 
    at com.google.gwt.core.client.impl.Impl.apply(Impl.java) 
    at com.google.gwt.core.client.impl.Impl.entry0(Impl.java:214) 
    at sun.reflect.GeneratedMethodAccessor56.invoke(Unknown Source) 
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25) 
    at java.lang.reflect.Method.invoke(Method.java:597) 
    at com.google.gwt.dev.shell.MethodAdaptor.invoke(MethodAdaptor.java:103) 
    at com.google.gwt.dev.shell.MethodDispatch.invoke(MethodDispatch.java:71) 
    at com.google.gwt.dev.shell.OophmSessionHandler.invoke(OophmSessionHandler.java:157) 
    at com.google.gwt.dev.shell.BrowserChannelServer.reactToMessages(BrowserChannelServer.java:281) 
    at com.google.gwt.dev.shell.BrowserChannelServer.processConnection(BrowserChannelServer.java:531) 
    at com.google.gwt.dev.shell.BrowserChannelServer.run(BrowserChannelServer.java:352) 
    at java.lang.Thread.run(Thread.java:680) 
Caused by: com.google.gwt.core.client.JavaScriptException: (TypeError): $doc.applet_id.doSomething is not a function 
+0

看看这里http://www.rgagnon.com/howto.html下的Java/JavaScript的互动如何与普通的JS – 2010-11-07 15:24:26

+0

@Romain做:为链接的感谢,但相对于特定的主题,我发现甲骨文NE孙更实用的网站和免费的垃圾邮件:http://download.oracle.com/javase/tutorial/deployment/applet/invokingAppletMethodsFromJavaScript.html – Carl 2010-11-07 15:45:05

回答

4

显然我的JNLP文件还需要

<param name="MAYSCRIPT" value="true"/>

<applet-desc>部。然而,将MAYSCRIPT:true添加到属性似乎不起作用。

+0

我的理解是,使用JNLP部署的Applet(甚至是嵌入式的,使用插件 - 英寸架构)无法访问JavaScript。 :(请注意,这只是我的理解是,我不是100%肯定 – 2010-11-05 08:49:50

+0

@Andrew:!以上的作品,所以我觉得你的理解可能不完整 – Carl 2010-11-05 13:16:40

+0

谢谢你的纠正,我已给人们错误的信息。不幸的是,我无法看到问题在这里,但如果我有任何灵感,我会回去。 – 2010-11-06 01:53:14