title: GWT JSNI: invoking applet methods?
body: <p>I have a <a href="http://code.google.com/webtoolkit/" rel="nofollow">GWT</a> application that includes an embedded applet.</p>
  
  <p>I would like to use JNSI to let GWT buttons push data to that applet, but at the moment I can't even get it to connect.  Looking for some help - can't seem to find anything addressing how to make things talk.</p>
  
  <p>In my entrypoint class I define:</p>
  
  <pre><code> native void doSomething() /*-{
    $doc.applet_id.doSomething();
   }-*/;
  </code></pre>
  
  <p>Which I hook via ClickHandler to a Button.  Within the applet main class, there is a <code>doSomething()</code> method, and in the page I launch the applet via:</p>
  
  <pre><code> &lt;script&gt;
    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);
   &lt;/script&gt;
  </code></pre>
  
  <p>The stack trace is</p>
  
  <pre><code> 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
  </code></pre>