views:

246

answers:

2

I currently have a Java Applet which contains a method callfromjs(). Javascript calls this method from the applet so that I don't have to deal with the clunky applet GUI, and then I can create the responses on the DOM easily from javascript.

The problem is that the browser hangs while first loading the applet. To get around this, I figured I could use AJAX. The AJAX calls a PHP file which contains callfromjs(). The problem is that the request returns because it's PHP, and it doesn't wait for callfromjs() to retrieve the content.

On to my questions:

  1. Is there a better way to handle this?
  2. If this method seems ok, how can I force the request not to return until the javascript is finished calling the method from the applet?
A: 

I'm not sure I understand what's going on here. Are you looking to generate content via an applet without having the applet perform the GUI work itself ? And are you stuck since the applet takes a long time to load ?

So why not dispense with the applet, extract the important stuff and make it available as a servlet ? Interact with it via (say) DWR, which allows AJAX calls to a Java backend (via exposing Java objects automatically as Javascript object). That means your client GUI will be fast/responsive and you have no applet reliance.

Brian Agnew
Taking a look at DWR now. The applet that I use is signed - would this be a problem in something like DWR or would the same "Do you trust this application?" dialog be shown?
DiglettPotato
You don't have any Java code client side. It's all Javascript on the browser.
Brian Agnew
Ok, so DWR wouldn't work for this. I need Java to run from the client, not from the server.
DiglettPotato
A: 

So the problem is a LiveConnect call into the applet hangs whilst the applet is initialised?

The obvious solution would be for the JavaScript to initially ignore the applet. When the applet is initialised it can then call into the JavaScript to enable.

Tom Hawtin - tackline
That's true. The problem though is that I am only using the applet for a specific function of the page. So I'd rather not have every user hang because the applet needs to initialize, if they don't use that function.
DiglettPotato
With PlugIn2 the pause when while starting to initialise the plug-in should be quite small. I guess you could use JavaScript to add the applet/object tag to the page dynamically - obviously know AJAX required for that.
Tom Hawtin - tackline
I ended up using javascript to add an iframe to the page dynamically (which contained the applet).
DiglettPotato