On Monday, April 2, 2012 10:26:27 PM UTC+2, Geoffrey Wiseman wrote:
>
> I have a piece of GWT code that I wanted to invoke from outside 
> handwritten JavaScript. There's an example shown here under "Calling a Java 
> method from Handwritten JavaScript":
>
> https://developers.google.com/web-toolkit/doc/latest/DevGuideCodingBasicsJSNI
>
> That example uses a static method; I can make that work, but my first 
> instinct was that i'd rather use an instance, so using the syntax shown 
> under JSNI invocations, I tried:
>
> /* package */ native void exportJavascriptMethods( PreviewPane x ) /*-{
>        $wnd.imageSelected =
>           $entry(this
> @ca.cpp.spike.gwtapplet.client.PreviewPane::imageSelected
> (Ljava/lang/String;Ljava/lang/String;));
>   }-*/;
>
> That doesn't work. Eclipse (and the GWT compiler) complain:
> "JavaScript parsing: Missing ) after argument list PreviewPane.java"
>

You're missing the '.' before the '@', so it might be the issue (the parser 
chokes on the '@' and says the $entry() call is missing its closing paren, 
or something like that).

You'll have another issue when you fix this syntax error though: you get a 
reference on the method but, like in Java with java.lang.reflect.Method, 
the instance it's called on has to be given at call time.
You have to write:
   var that = this;
   $wnd.imageSelected = $entry(function(s1, s2) {
         return 
[email protected]::imageSelected(Ljava/lang/String;Ljava/lang/String;)(s1,
 
s2);
      });

About the "var that = this;", see 
http://www.yuiblog.com/blog/2012/03/30/what-is-the-meaning-of-this

-- 
You received this message because you are subscribed to the Google Groups 
"Google Web Toolkit" group.
To view this discussion on the web visit 
https://groups.google.com/d/msg/google-web-toolkit/-/arV8TNOAk7gJ.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to 
[email protected].
For more options, visit this group at 
http://groups.google.com/group/google-web-toolkit?hl=en.

Reply via email to