2010-11-04 94 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