Note that there are some explanatory texts on larger screens.

plurals
  1. POCalling Java methods from inner function of GWT JSNI
    text
    copied!<p>I'm using W3C Geolocation API in order to retrieve location information within GWT web application. Geolocation API is built the way that callback function gets invoked as soon as location position is retrieved.</p> <p>My current test code looks as follows:</p> <pre><code>public native void getCoordinates() /*-{ function onPositionUpdate(position) { var lat = position.coords.latitude; var lng = position.coords.longitude; var alt = position.coords.altitude; // not OK,- doesn't get invoked, and function execution stops at this point this.@com.test.GpsPanel::testMethod()(); alert("Coordinates retrieved: " + lat + ";" + lng + ";" + alt); } function onPositionUpdateFailed(error) { alert("Some error"); } if(navigator.geolocation) { // OK when invoked somewhere here this.@com.test.GpsPanel::testMethod()(); navigator.geolocation.getCurrentPosition(onPositionUpdate, onPositionUpdateFailed); } else { alert("Geolocation is not available"); } }-*/; </code></pre> <p>I'm trying to demonstrate that the method <code>testMethod</code> doesn't get invoked from inner method <code>onPositionUpdate</code>. Even more: no alert is shown afterwards (it does get shown when testMethod call is removed), but no warnings or errors are found in a log.</p> <p>My question is: how do I reference this method from the inner function? I have feeling that <code>this.</code> is not a correct reference from the inner functions. If Java class cannot be referenced correctly, then what are the possible workarounds? Please note that I cannot pass anything else to function <code>onPositionUpdate()</code> as it's a callback function.</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