Search code examples
gwtjsni

How to call java method from javascript method that located within another jsni method


 public class A{
    private void javaMethod(int a,int b){}

    private native void init()/*-{
            function OnMouseMove(e) {
             //blow calling doesn't work
              this.@p::javaMethod(Ljava/...teger;Ljava.../Integer;)(intVal,intVal);
            }
    }-*/;
  }

As described above,how to make that invoking work?


Solution

  • Answered on the Google Group: https://groups.google.com/d/msg/google-web-toolkit/qE2-L4u_t4s/YqjOu-bUfsAJ

    Copied here for reference and convenience:

    First, int is not java.lang.Integer, so your method signature in JSNI is wrong; it should read javaMethod(II). (I suppose the @p:: while javaMethod is defined in class A is over-simplification in your question, but is OK in your code)

    You'll also probably have a problem with this, that might not be what you think it is. A common pattern is to assign the current object (this, at the time) to a variable that you'll reference from your closure:

    var that = this;
    …
    function OnMouseMove(e) {
       [email protected]::javaMethod(II)(intVal, intVal);
    }