Monday, August 1, 2011

Re: Using Java Interfaces in JSNI

Hi Thanks for your answer.

I have tried and I am getting some weird js error message
"this.setPosition is not a function" referring to a random line from
the html file itself, so it looks like firebug is completely lost.

My code is:

public native UniMarkerJSNI addEditableMarker(HasEditableMarker
hasEditableMarker, double lat, double lng, String mapIconUrl, int
shiftX, int shiftY) /*-{
var callback = function(marker) {
var eoLatLng =
@com.metaaps.webapps.earthimages.shared.domain.EOLatLng::new(DD)
(marker.getLat(), marker.getLng());
alert("test1");

hasEditableMarker.@com.metaaps.webapps.earthimages.shared.domain.implementation.HasEditableMarker::updatePosition(Lcom/
metaaps/webapps/earthimages/shared/domain/EOLatLng;)(eoLatLng);
alert("test2");
};
var marker = new $wnd.mapsJSNI.uniMarker(lat, lng, mapIconUrl,
shiftX, shiftY, callback);
marker.setDraggable(callback);
return marker;
}-*/;

alert test1 is triggered no problem.

alert test2 is never triggered so it seems the problem occurs when
calling the interface method implementation from the object. My
interface method implementation is really simple, just assigning the
value to a field:

@Override
public void updatePosition(EOLatLng pos) {
this.pos = pos;
}

I have no clue as to how to sort this out...


On Jul 27, 6:09 pm, Alain Ekambi <jazzmatad...@googlemail.com> wrote:
> Yes it s possible.
> But you might want to  actually call the function in the JSNI in the right
> way.(see bold entry)
>
> public native void makeUseOfI(I myObjectAorB) /*-{
>     var val = myObjectAo...@pkg.I*::*myInterfaceFunction()*();*
>     $wnd.whateverFunction(val)
>
> }-*/;
>
> 2011/7/27 Thomas Lefort <lefortho...@gmail.com>
>
>
>
>
>
>
>
>
>
> > Hi,
>
> > I have the following:
>
> > interface I {
> >     myInterfaceFunction
> > }
>
> > A implements I {
> > }
>
> > B implements I {
> > }
>
> > I want to pass A or B using interface I to a js code I am writting, ie
>
> > public native void makeUseOfI(I myObjectAorB) /*-{
> >     var val = myObjectAo...@pkg.I.myInterfaceFunction();
> >     $wnd.whateverFunction(val)
> > }-*/;
>
> > Is this possible?
>
> > Thanks,
>
> > Thomas
>
> > --
> > You received this message because you are subscribed to the Google Groups
> > "Google Web Toolkit" group.
> > To post to this group, send email to google-web-toolkit@googlegroups.com.
> > To unsubscribe from this group, send email to
> > google-web-toolkit+unsubscribe@googlegroups.com.
> > For more options, visit this group at
> >http://groups.google.com/group/google-web-toolkit?hl=en.
>
> --
>
> GWT API for  non Java based platformshttp://code.google.com/p/gwt4air/http://www.gwt4air.appspot.com/

--
You received this message because you are subscribed to the Google Groups "Google Web Toolkit" group.
To post to this group, send email to google-web-toolkit@googlegroups.com.
To unsubscribe from this group, send email to google-web-toolkit+unsubscribe@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/google-web-toolkit?hl=en.

No comments:

Post a Comment