How to call JSNI function from Javascript function?

Here are examples of call buttons in html:

<input type='button' value='Call' onclick='Test()'> 

And here are some functions that I tried and which did not work:

 <script type="text/javascript"> function Test() { com.tests.client.Test_GoogleWeb_JSNI::Callee()(); } </script> 

But we cannot call Callee (). How can we achieve this? I mean, how can we call a JSNI function from javascript?

Help will be appreciated.

+4
source share
3 answers

It is very easy. You need to "export" your function written to GWT (or it may be another JSNI function).

Here is the relevant documentation: http://code.google.com/webtoolkit/doc/latest/DevGuideCodingBasicsJSNI.html#calling

So in your case:

In the GWT code:

 public static void Caller() /*-{ ... }-*/ public static native void exportStaticMethod() /*-{ $wnd.Callee = $entry(@com.tests.client.Test_GoogleWeb_JSNI::Callee()); }-*/; 

Then you call exportStaticMethod() somewhere, even in your onModuleLoad. & L; <YOU SHOULD DO IT

You can then call Callee() from your javascript handwritten code.

Your code for the button:

 <input type='button' value='Call' onclick='$wnd.Callee();'> 
+7
source

For chrome, this solution works if I change onclick = '$ wnd.Callee () to onclick =' window.Callee (). The Chrome browser console tells us that $ wnd is undefined. $ wnd is access to the browser window object in JSNI.

Sorry, I couldn’t just leave this as a comment (not enough points)

+1
source

Look here :

  • Make sure Test_GoogleWeb_JSNI.Callee() static .
  • Assign the Callee () function to a window object.
0
source

Source: https://habr.com/ru/post/1396393/


All Articles