Announcement

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

    JavaScriptObject

    I am trying to invoke a javascript function within an iframe. My servlet returns:

    <script type="text/javascript">window.top.callback0("HELLO");</script>

    I have the following code:

    Code:
    public interface JavaScriptMethodCallback
    {
    	public void execute(JavaScriptObject obj);
    }
    Code:
    	private native static void createCallbackFunction(JavaScriptMethodCallback obj, String callbackName)/*-{
    		tmpcallback = function( j ){
    		$wnd.alert(j);
    		obj.@client.JavaScriptMethodCallback::execute(Lcom/google/gwt/core/client/JavaScriptObject;)( j );
    		};
    		$wnd[callbackName]=tmpcallback;
    	}-*/;
    Code:
    ....
    JavaScriptMethodHelper.registerCallbackFunction(new JavaScriptMethodCallback() {
    			public void execute(JavaScriptObject obj)
    			{
    				System.err.println(obj.toString());
    			}
    		});
    ....
    The function call was successfully invoked, because I get an alert box from this line:

    Code:
    $wnd.alert(j);
    However, I am getting a "uncaught exception: java.lang.ClassCastException" after the alert box according to Firebug and my Java system println was not executed. Can you point out what I am missing?

    Thx.

    #2
    This isn't really a SmartGWT question, just a GWT question, but probably it's because you're passing a String "HELLO", when when passed through JSNI becomes a Java String, not a JavaScriptObject. JavaScriptObject is used to represent Object, Array and potentially Date.

    Comment

    Working...
    X