javagwtjsni

JSNI (call from javascript to java)


In the JSNI example to call a Java method from Javascript, they write this:

$wnd.testJSNI = @com.jsni.client.HelloJSNI::testJSNI(Ljava/lang/String;)(test);

I tried to figure it out, but couldn't find what exactly is meant by Ljava/lang/String? Am I required to pass these arguments?


Solution

  • The Ljava/lang/String; tells GWT that the method expects a String parameter, which will be passed in as the test value in your sample code.

    In general in JSNI methods you need to tell GWT what the parameter types are, or you can use the shortcut (*) which tells GWT to figure it out for itself. This works in most cases as far as I've seen. So your code could also be written as:

    var test = 'This is my test string';
    $wnd.testJSNI = @com.jsni.client.HelloJSNI::testJSNI(*)(test);