On Sunday, October 19, 2014 1:46:42 AM UTC+2, Magnus wrote:
>
> Hi,
>
> I want to define a hover handler in Java and reference it from JavaScript 
> in order to register it in a JS library:
>
> But the reference causes an error:
>
> public class MyClass
> {
> public native void myHandler (JavaScriptObject e) // don't know if 
> JavaScriptObject is the right type
>
>
You could also use com.google.gwt.dom.client.NativeEvent (and wouldn't need 
JSNI).
 

>  /*-{
>     var c = e.target.className;
>     console.log (c);
>  }-*/;
>
>  private native void startHover (String stl_w)
>  /*-{
>   var f = [email protected]::myhandler; // produces syntax error
>
>
Should be 
[email protected]::myHandler(Lcom/google/gwt/core/client/JavaScriptObject;), 
or [email protected]::myHandler(*), or just this.@myWidget::myHandler(*) 
in GWT 2.7 (resolves class names relative to package and imports).
 

>
>   $wnd.myLib.hover (f); // register handler in the external library
>
>
That won't work the way you expect it to, because the 'this' inside 
myHandler won't be an instance of MyClass/myWidget.
Exceptions occurring inside myHandler also won't be dispatched to 
GWT.UncaughtExceptionHandler, and scheduled commands (scheduleEntry, and 
scheduleFinally within myHandler) won't work; for that you need to wrap the 
function with $entry: f = $entry(f).

This would work best:

var self = this;
 $wnd.myLib.hover($entry(function(e) { self.@myWidget::myHandler(*)(e); }));

To sum up: your errors here are related to JSNI method reference syntax, 
and scope and 'this' in JavaScript.

-- 
You received this message because you are subscribed to the Google Groups 
"Google Web Toolkit" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To post to this group, send email to [email protected].
Visit this group at http://groups.google.com/group/google-web-toolkit.
For more options, visit https://groups.google.com/d/optout.

Reply via email to