title: Are Java Applets unable to communicate with javascript within Firefox on Mac OS?
body: <p>I have a java applet running in a browser that is calling some javascript functions and expecting a result from theses functions. This is working with the following configurations :</p>
  
  <ul>
  <li>Internet Explorer</li>
  <li>FireFox / Windows</li>
  <li>Safari / Mac</li>
  </ul>
  
  <p>BUT It's not working with Firefox on MAC OS</p>
  
  <p>The source of the problem seems to be the win.eval calls that always return null.
  I tested this with Firefox 3.0.6 on a Mac OS X 10.4.11 </p>
  
  <p>A bit of code : </p>
  
  <pre><code>JSObject win = (JSObject) JSObject.getWindow(this);
  Object exp = win.eval("testfunc()");
  System.out.println("exp = " + exp.toString());
  </code></pre>
  
  <p>This triggers a java.lang.NullPointerException (exp.toString()) statement).
  The testfunc javascript function just returns true.</p>
  
  <p>I tried with win.call and got the same result.</p>
  
  <p>My applet tag includes the mayscript and scriptable attributes.</p>
  
  <hr>
  
  <p>I found the answer thanks to Tristan. Testing his solution I created a really simple test that could work and worked my way to find the culprit. I was sure I did my tests with an empty testfunc() that just returned true, but I probably didn't because in that case it DOES work.
  The real problem here was that the function called a public method of the applet. Liveconnect doesn't seem to be able to handle that case in Firefox Mac.</p>
  
  <p>Let me give you an example :</p>
  
  <p>Java class : </p>
  
  <pre><code>public class MyApplet extends Applet {  
       public int getMyValue() {
           return 5;
       }
  
       public void somefunction() {
           JSObject win = (JSObject) JSObject.getWindow(this);
           Object exp = win.eval("jsfunc()");
           System.out.println("exp = " + exp.toString());
       }
  }
  </code></pre>
  
  <p>And the javascript code :</p>
  
  <pre><code>function jsfunc() {
      var myApplet = document.getElementById("applet_id");
      return myApplet.getMyValue() + 5;
  }
  </code></pre>
  
  <p>exp will be null in somefunction BECAUSE jsfunc calls the getMyValue() method of the applet. If you remove all calls to properties of the applet you're cool.<br>
  To solve my problem I decided to give all the values of the applet that I neeeded as parameters of my javascript function and I'm good now.<br>
  That may not be the case always, if the javascript changes the state of the applet ...I was lucky :)</p>