Note that there are some explanatory texts on larger screens.

plurals
  1. POCalling GWT methods from handwritten Javascript
    text
    copied!<p>Im building a web application with GWT and I want to give users the ability to extend its functionality by some sort of Javascript API that would interact with the app core written in GWT. Basically, this JS API would map to some of my GWT internal methods that would do the actual job.</p> <p>So, to achieve this, i read on GWT JSNI official documentation a trick that consists in creating a global JS variable from GWT and assigning it a call to the actual GWT method. Then i would make the call in my handwritten JS code through this variable. </p> <p>Unfortunately I couldnt make it to work (the example contained syntax errors son im not sure that it has even been tested). Doing more research, i found on this site a similar solution that assigns the JS var an anonymous function that makes the call. It looks like this: </p> <pre><code>/*GWT code that assigns the anonymous function*/ private static native void loadWrapper() /*-{ $wnd.showMessage = $entry(@com.Glob3Mobile.client.TestApi::msgBox()); }-*/; public static void msgBox() { Window.alert("hello"); } </code></pre> <p>This solution looks promising but I havent been able to make it to work. When i do "window.showMessage();" in my handwritten JS code it wont work. I have found these issues:</p> <ul> <li>window.showMessage seems to be created but JS console says that its not a function, even though i inspected the dom tree and verified that the variable does contains a function.</li> <li>It seems like I always have to append the "window." preffix, since the var is being created within the window object. This is a considerably concerning issue, cause forcing users to write like this every time they want to call a function is really tedious. </li> </ul> <p>If anybody knows the solution to these issues (or an alternative approach to achieve what im trying to do), id be very grateful to hear. Thanks in advance.</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload