By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
434,741 Members | 1,973 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 434,741 IT Pros & Developers. It's quick & easy.

Java Applet<-->JavaScript communication (Firefox 3).

P: n/a
I only need to support Firefox 3 at the moment, so any advice can be
specific to that.

I have a Java Applet, lets call it HelperApplet.

It has one method of importance:
public Object doHelp(JSObject callback) {
System.out.println(callback + "\n" + callback.getMember("foo"));
callback.call("helped", new Object[] {callback.getMember("foo")});
return callback;
}

I have javascript that does this:

myCallback = documents.applets[0].doHelp({
foo: "bar",
helped: function(result) {
alert(result);
}
});

Unfortunately, the callback doesn't get called. It appears the the
JSObject callback doesn't contain any members in Java land. Although, I
can access the returned object, eg myCallback.helped("Broken Java") works.

Any advice? Work-arounds? Are my attempts probably going to be futile?

Thanks,
Daniel.

--
Daniel Pitts' Tech Blog: <http://virtualinfinity.net/wordpress/>
Sep 24 '08 #1
Share this Question
Share on Google+
1 Reply


P: n/a
Daniel Pitts wrote:
I only need to support Firefox 3 at the moment, so any advice can be
specific to that.

I have a Java Applet, lets call it HelperApplet.

It has one method of importance:
public Object doHelp(JSObject callback) {
System.out.println(callback + "\n" + callback.getMember("foo"));
callback.call("helped", new Object[] {callback.getMember("foo")});
return callback;
}

I have javascript that does this:

myCallback = documents.applets[0].doHelp({
foo: "bar",
helped: function(result) {
alert(result);
}
});

Unfortunately, the callback doesn't get called. It appears the the
JSObject callback doesn't contain any members in Java land. Although, I
can access the returned object, eg myCallback.helped("Broken Java") works.

Any advice? Work-arounds? Are my attempts probably going to be futile?

Thanks,
Daniel.
I figured out a work around, not pretty, but it does the trick:

public class MyApplet extends JApplet {
private JSObject appletTmp;

public JSObject resolveObject(Object o) {
final int hashCode = System.identityHashCode(o);
appletTmp.setMember("toResolve" + hashCode, o);
return (JSObject) appletTmp.getMember("toResolve" + hashCode);
}

public void init() {
if (appletTmp == null) {
final JSObject window = JSObject.getWindow(this);
final String tmpName = "_AppletTmp" +
System.identityHashCode(this);
window.eval("var "+ tmpName +" = {}");
appletTmp = (JSObject)window.getMember(tmpName);
}
}

public Object doHelp(Object o) {
JSObject callback = resolveObject(o);
System.out.println(callback + "\n" + callback.getMember("foo"));
callback.call("helped", new Object[] {callback.getMember("foo")});
return callback;
}
}

--
Daniel Pitts' Tech Blog: <http://virtualinfinity.net/wordpress/>
Sep 25 '08 #2

This discussion thread is closed

Replies have been disabled for this discussion.