I'm trying to call a Java method form a part of Javascript code.
I've read Accessing Java Methods and Fields from JavaScript and I
think I've reproduced something equivalent but it does not work.

Here is my HTML page :
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://
www.w3.org/TR/html4/loose.dtd">
<html>
  <head>
    <meta http-equiv="content-type" content="text/html;
charset=UTF-8">
    <script type="text/javascript" language="javascript">
        var abcd = getJavaValue();
    </script>
    <script type="text/javascript" language="javascript"
src="com.eloquant.test.test.nocache.js"></script>
  </head>
  <body>
  </body>
</html>

Here is the java code :
package com.eloquant.test.client;

import com.google.gwt.core.client.EntryPoint;
import com.google.gwt.user.client.ui.HTML;
import com.google.gwt.user.client.ui.RootPanel;

public class Test implements EntryPoint {

        public void onModuleLoad() {

                exportStaticMethod();

                RootPanel.get().add(new HTML ("abcd =" + getAbcd()));
        }

    public static int getValue() {
        return 1;
    };

    public static native void exportStaticMethod() /*-{
       $wnd.getJavaValue = @com.eloquant.test.client.Test::getValue();
    }-*/;

        public native int getAbcd () /*-{
                return $wnd.abcd;
        }-*/;
}


When I run the app I get the following error :
com.google.gwt.dev.shell.HostedModeException: Expected primitive type
int; actual value was undefined
        at com.google.gwt.dev.shell.JsValueGlue.get(JsValueGlue.java:51)
        at
com.google.gwt.dev.shell.ModuleSpace.invokeNativeInt(ModuleSpace.java:
193)...


If I replace in the HTML
        var abcd = getJavaValue();
By
        var abcd = 5;

I've got a correct display, so Java calling Javascript is Ok, but I
don't understand what's wrong with javascript calling java.

Does any one have some ideas ?
Thanks for reading




--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups 
"Google Web Toolkit" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/Google-Web-Toolkit?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to