473,387 Members | 1,575 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,387 software developers and data experts.

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

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
1 5901
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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

0
by: Ronald Carter | last post by:
Ok, I go to http://sidestep.com and use the web interface to search a flight. When using Mozilla, if I click the calendar button to set the travel date, I get a little calendar window from which I...
2
by: annie | last post by:
Hi all. Can Java classes/objects be used from within the javascript code on the HTML page? I.e., can I call a Java method from the javascript function? Thanks in advance Anna
1
by: Uma | last post by:
DB2I.PROCEDURE1 - Build started. C:\SQLLIB\java\jdk\bin\javac -classpath ".;C:\SQLLIB\java\db2java.zip;C:\SQLLIB\java\runtime.zip;C:\SQLLIB\java\sqlj.zip" "PROCEDURE1.java" DB2I.PROCEDURE1 -...
1
by: Praveen | last post by:
Hi, I have installed WebSphere Portal on AIX and connected to DB2 on a remote machine, Getting the followin errors when trying to get the values from database thru applications installed on...
4
by: jediknight | last post by:
Hi, I am trying to establish whether I can have a C# socket server and Java socket clients. From all the examples I have seen on the web refer to Java Servers and C# clients. Can anyone point...
5
mrjohn
by: mrjohn | last post by:
I've been experimenting with this Java applet and Firefox, but after I recompile the code and refresh/reopen the page, the changes are not reflected in the browser. Why's that? import...
3
by: hash4sp | last post by:
Hello Can anyone here please guide me with the Cross Domain Communication between IFrames. Problem: Application1 running on IIS => http://localhost.ad.local/Applicaiton1 Application2...
0
by: adbasque | last post by:
Hello, I am running a chat server with a java Applet unfortunately I don't have access to the source code, all I have are jars and classes. When I run the applet with FF2, IE, Safari and Opera...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.