First, yes I have searched already and found this answer already:
GWT JSNI – problem passing Strings
I’m trying to call a java method from a JSNI method, but not getting anywhere. I’ve tried the advice given above, but it still won’t work.
Here’s the code:
public native void initCustomListeners(MapmakerMapViewPresenter.MyView view) /*-{
//public native void initCustomListeners() /*-{
$wnd.getLocationDescriptions = function(lng, lat) {
$entry(view.@org.jason.mapmaker.client.view.MapmakerMapViewImpl::getLocationDescriptions(DD)(lng, lat));
}
$wnd.google.maps.event.addListener(map, 'click', function(event) {
var lat = event.latLng.lat().toFixed(3);
var lng = event.latLng.lng().toFixed(3);
alert("(" + lat + ", " + lng + ")");
$wnd.getLocationDescriptions(lng, lat);
alert("Test!");
});
}-*/; @Override
public void getLocationDescriptions(double lng, double lat) {
getUiHandlers().doGetLocationDescriptions(lng, lat);
}
Can anyone help me out?
Jason
I don’t know if that’s the issue (you don’t even say how that code behaves vs. how you expect it to behave) but there are a few bugs in your code:
$entrywraps a function, so you have to call the function it returns, rather than (uselessly) wrap the result of the function after calling it!I.e.
$entry(function(lat,lng) { foo.@bar.Baz::quux(DD)(a, b); }rather than$entry(foo.@bar.Baz::quux(DD)(a, b))you
addListeneron amapbut that variable is never defined.