I need to check if a variable was defined in javascript and I tried
with the following native method:

private native Boolean isADefined() /*-{
    return @java.lang.Boolean::valueOf(Z)($wnd.a != undefined);
}-*/;

but when it is called, the following exception is thrown:

com.google.gwt.dev.shell.HostedModeException: invoke arguments: JS
value of type int, expected boolean
    at com.google.gwt.dev.shell.JsValueGlue.get(JsValueGlue.java:100)
    at
com.google.gwt.dev.shell.MethodDispatch.invoke(MethodDispatch.java:65)
    at
com.google.gwt.dev.shell.OophmSessionHandler.invoke(OophmSessionHandler.java:
157)
    at
com.google.gwt.dev.shell.BrowserChannel.reactToMessagesWhileWaitingForReturn(BrowserChannel.java:
1713)
    at
com.google.gwt.dev.shell.BrowserChannelServer.invokeJavascript(BrowserChannelServer.java:
165)
    at
com.google.gwt.dev.shell.ModuleSpaceOOPHM.doInvoke(ModuleSpaceOOPHM.java:
120)
    at
com.google.gwt.dev.shell.ModuleSpace.invokeNative(ModuleSpace.java:
507)
    at
com.google.gwt.dev.shell.ModuleSpace.invokeNativeObject(ModuleSpace.java:
264)
    at
com.google.gwt.dev.shell.JavaScriptHost.invokeNativeObject(JavaScriptHost.java:
91)
...

It seems that the boolean expression is evaluated as an integer. Other
than

private native Boolean isADefined() /*-{
    if ($wnd.a != undefined) {
        return @lava.lang.Boolean::TRUE;
    } else {
        return @lava.lang.Boolean::FALSE;
    }
}-*/;

is there a (more elegant) way to call the boolean constructor with a
javascript boolean expression?

-- 
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