0

What I want is to call this code

public native void eventClickHandler( String id) /*-{
  $wnd.jQuery('#' + id).bind('jqplotDataClick',function(ev, seriesIndex, pointIndex, data) {
    this.@it.codegen.gwt.jqplot.client.charts.JQChart::onClick(Ljava/lang/String;Ljava/lang/String;)(seriesIndex, pointIndex);
  });
}-*/;

Here the onClick method is a normal java method and I'm using GWT and JSNI interface for this. Thanks in advance!..

Thomas Broyer
  • 64,353
  • 7
  • 91
  • 164
Juliyanage Silva
  • 2,529
  • 1
  • 21
  • 33
  • its not working sorry I think I forgot to mention it. – Juliyanage Silva May 03 '12 at 12:05
  • possible duplicate of [GWT/JSNI this. is not replace with a reference to the instance](http://stackoverflow.com/questions/10406769/gwt-jsni-this-is-not-replace-with-a-reference-to-the-instance) – Thomas Broyer May 03 '12 at 12:24
  • 1
    [the use of `this` is somewhat risky](http://www.quirksmode.org/js/this.html), as it refers to the function owner. is the JSNI method a member of an [overlay type](http://code.google.com/p/google-web-toolkit/wiki/OverlayTypes)? please enclose more context code, and some generated exceptions, if exist. – Eliran Malka May 04 '12 at 17:43

1 Answers1

1

Have you used jQuery before? this has particular meaning inside a function passed to jQuery. Even in JSNI, while it is in a Java file, it won't behave like a Java this, but like a JavaScript this.

Try this instead:

public native void eventClickHandler( String id) /*-{
  var origThis = this;
  $wnd.jQuery('#' + id).bind('jqplotDataClick',function(ev, seriesIndex, pointIndex, data) {
    origThis.@it.codegen.gwt.jqplot.client.charts.JQChart::onClick(Ljava/lang/String;Ljava/lang/String;)(seriesIndex, pointIndex);
  });
}-*/;
Colin Alworth
  • 17,801
  • 2
  • 26
  • 39