Thursday, June 2, 2016

Re: Having trouble with GWT JSNI

Hi Thomas,

Thank you very much, it is working now. I really really appreciate the help you've given me.

Andrew

On 02/06/16 15:14, Thomas Broyer wrote:


On Thursday, June 2, 2016 at 3:50:49 PM UTC+2, Andrew Ferguson wrote:
Hi Thomas,

Thank you *so* much (I'm kicking myself because it was such a simple error!).

I don't suppose you know how I could call an external JavaScript function from inside the GWT project? I cannot find any examples online that show this.


public static native boolean thatJsFunction(int param1, String param2, double param3) /*-{
  return $wnd.that_js_function(param1, param2, param3);
}-*/;

Or do you mean also loading the JS script?

BTW, you may want to start using GWT 2.8 (prefer the snapshot to the beta1, if you can) and JsInterop: https://docs.google.com/document/d/10fmlEYIHcyead_4R1S5wKGs1t2I7Fnp_PaNaa7XTEk0/edit

The equivalent of the above JSNI would be:

@JsMethod(namespace=JsPackage.GLOBAL)
static native boolean that_js_function(int param1, String param2, double param3);

The equivalent of the JSNI that exposes your function would be:

@JsMethod(namespace=JsPackage.GLOBAL)
public static int js_funct_equiv(int myNum) {
  return myNum;
}
(you'd need to pass the GWT compiler the --generateJsInteropExports flag to export your method though.
--
You received this message because you are subscribed to the Google Groups "GWT Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to google-web-toolkit+unsubscribe@googlegroups.com.
To post to this group, send email to google-web-toolkit@googlegroups.com.
Visit this group at https://groups.google.com/group/google-web-toolkit.
For more options, visit https://groups.google.com/d/optout.

No comments:

Post a Comment