Announcement

Collapse
No announcement yet.
X
  • Filter
  • Time
Clear All
new posts

    Applet Communication SmartGWT 2.4

    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:
    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());
        }-*/;
    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:
    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();
    		}
        }
    SmartGWT/Javascript Code:
    Code:
        public static native String smartGWTMethod()/*-{
    		function smartGWTMethod()
    		{
        		return "smaretGWTMethod, misspeled on popuse! value";
    		}
        }-*/;
    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
    Last edited by yhc_vlc; 13 Dec 2011, 02:33.

    #2
    I'm about to embark on just this same requirement. Were you ever able to get a Java applet to call a SmartGWT method? Any pointers from Isomorphic?

    Comment


      #3
      The original poster's code is not going to work because that function is not global, it will be created inside of the other function. You need to create a global function.

      The following is completely untested:

      Code:
      public static native void setupSmartGWTMethod()/*-{
        window.smartGWTMethod  = function (){
          return "smaretGWTMethod, misspeled on popuse! value";
        };
      }-*/;
      If you actually need to return something useful, look into the calling conventions for how to call Java functions from JavaScript.

      Comment


        #4
        It has been a while, but i believe the problem was that i did not publish the methods. Here is a short example

        Code:
                private native void publishJavaScriptFunctions()/*-{
        		$wnd.smartGWTMethod = @package.package.package::smartGWTMethod(Ljava/lang/String;);
                }-*/;
        More information can be found in the following links.
        http://code.google.com/webtoolkit/do...asicsJSNI.html
        http://googlewebtoolkit.blogspot.com...rt-1-jsni.html

        Good luck!

        Comment

        Working...
        X