This question is about the communication (or method / function invocation ) between an applet and SmartGWT 2.4. Unfortunately the applet cannot be replaced so I'm stuck with it.
I have been able to add an applet into SmartGWT using the prescribed com.smartgwt.client.widgets.plugins.Applet. Now I am trying to get the communication between the applet and smartgwt to work.
The communication from javascript to the Applet is working using the following implementation:
Applet Code:
SmartGWT Code:
When invoking the callAppletMethod an alert pops up with "apletMethod! value".
However I can't get the reverse to work - a method call from the applet to SmartGWT. I've tried this using the following code:
Applet Code:
SmartGWT/Javascript Code:
When I call the method i get this exception when running it in Chrome
'Uncaught JavaScript exception [Uncaught ReferenceError: smartGWTMethod is not defined] in , line 1"
Furthermore I have tried pasting this code in a basic HTML page and it works. So how do i get this to work in SmartGWT?
Thanks!
edit:learnt the use of the "code" tag
I have been able to add an applet into SmartGWT using the prescribed com.smartgwt.client.widgets.plugins.Applet. Now I am trying to get the communication between the applet and smartgwt to work.
The communication from javascript to the Applet is working using the following implementation:
Applet Code:
Code:
public String appletMethod(){ return new String("apletMethod! value"); }
SmartGWT Code:
Code:
public static native void callAppletMethod()/*-{ //JSNI stuff which is required var loader = $doc.applets[0]; //there is a reference to my applet in the var appplet (duh) var applet = loader.getApplet(); //return the return value of the method alert(applet.appletMethod()); }-*/;
However I can't get the reverse to work - a method call from the applet to SmartGWT. I've tried this using the following code:
Applet Code:
Code:
public void callSmartGWTMethod(){ //get the handle to the document JSObject window = JSObject.getWindow(this); try { //this is where the call is acutally made Object result = window.call("smartGWTMethod", null); System.out.println(result.toString()); } catch (JSException e) { e.printStackTrace(); } }
Code:
public static native String smartGWTMethod()/*-{ function smartGWTMethod() { return "smaretGWTMethod, misspeled on popuse! value"; } }-*/;
'Uncaught JavaScript exception [Uncaught ReferenceError: smartGWTMethod is not defined] in , line 1"
Furthermore I have tried pasting this code in a basic HTML page and it works. So how do i get this to work in SmartGWT?
Thanks!
edit:learnt the use of the "code" tag
Comment