rana
unread,Oct 19, 2010, 11:26:36 AM10/19/10Sign in to reply to author
Sign in to forward
You do not have permission to delete messages in this group
Either email addresses are anonymous for this group or you need the view member email addresses permission to view the original message
to Google Web Toolkit
I am running a java applet within GWT, and require 2 way
communication.
The applet exposes a public method to do something on the applet. No
problem here, I am able to call this method from my GWT class as
follows:
public static native String invokeOnApplet(String appletID) /*-{
var c = $wnd.document.getElementById(appletID).invokeOnApplet();
return c;
}-*/;
But implementing callback from the Applet is not working. However, I
am able to invoke a pure javascript function defined inside the html
HEAD tag.
My GWT entry class:
--------------------------------------------
public class MyClient implements EntryPoint {
public void onModuleLoad() {
exportCallbackFunction();
}
public static native void exportCallbackFunction() /*-{
$wnd.funcAppletToGWT = @MyClient::funcAppletToGWT(Ljava/lang/
String;Ljava/lang/String;);
}-*/;
public static void funcAppletToGWT(String funcType, String param) {
Window.alert("in funcAppletToGWT() : " + funcType + ", " + param);
}
}
--------------------------------------------
HTML code:
--------------------------------------------
<html>
<head>
<script LANGUAGE="JavaScript">
function funcOther(param1, param2) {
alert('in funcOther() : ' + param1 + ', ' + param2);
}
</script>
</head>
<body>
...
<button type="button"
onclick="funcAppletToGWT('FTYPEX','PARAM33')">test funcAppletToGWT</
button>
<applet name="..." id="..." codebase="..."
code="TestApplet.class" width="100%" height="100%"
archive="..." MAYSCRIPT>
<param name="JS_FUNC_NAME" value="funcAppletToJS" >
</applet>
...
</body>
</html>
--------------------------------------------
Applet code:
--------------------------------------------
import netscape.javascript.*;
public class TestApplet extends Applet {
...
public String invokeOnApplet() {
return "invoked on Applet";
}
public void actionPerformed(ActionEvent ae) {
JSObject win = (JSObject) JSObject.getWindow(this);
win.call(getParameter("JS_FUNC_NAME"), new Object[] {"FTYPEY",
"PARAM44"});
}
}
--------------------------------------------
On button click, funcAppletToGWT() is being correctly called. But when
I invoke the same from my applet, the applet throws the following
error:
[19/10 14:03:55 - AWT-EventQueue-2] ERROR:
[TestApplet.actionPerformed] failed to call javascript-function:
funcAppletToJS with params=[STANDARD_ORDER,20735]
reason: netscape.javascript.JSException: JavaScript error while
calling "funcAppletToJS"
netscape.javascript.JSException: JavaScript error while calling
"funcAppletToJS"
at
sun.plugin2.main.client.MessagePassingJSObject.newJSException(Unknown
Source)
at
sun.plugin2.main.client.MessagePassingJSObject.waitForReply(Unknown
Source)
at sun.plugin2.main.client.MessagePassingJSObject.call(Unknown
Source)
If I replace the exported method with a regular javascript function,
then the function gets invoked fine.
e.g. <param name="JS_FUNC_NAME" value="funcOther" >
Any pointer/help is appreciated.
regards,
Rana