Tuesday, December 29, 2015

JsInterop & 2.8.0-SNAPSHOT : calling Java Object in Javascript

hi,

I'm using JsInterop with GWT 2.8.0-SNAPSHOT and trying to use a "@JsType" annotated Java Object in a "js" file.

It works fine in super dev mode (gwt:run) but in "normal" mode (dev mode off) I have this exception (in the browser console) : "onClick is not a function"

Here is the Java Object, a home-made click handler : 
@JsType
public interface ITableClickHandler {  
  public void onClick(String rowId);  
  public void onDoubleClick(String rowId);
}

It's also declared as a property in my js file : (among other properties)
click_handler: {
    type: Object
},
 
And I set this property with the method below (the name matches the name of the js property), in a Java interface that wraps some web component element (but that's not relevant I think) :
@JsType(isNative = true)
public interface MyTableElement {   
 
  @JsProperty
  void setClick_handler(ITableClickHandler clickHandler); 

At some point in my js file, I do the following :
if (this.click_handler) {
    this.click_handler.onClick(row.id);
}
It allows me to catch this click event (okay just the row id) fired in the js file, with some GWT handler (implementing my interface ITableClickHandler).

And yes I use the new jsinterop.* annotations ;)

I don't really know if I'm "jsInteroping" properly... and maybe there is a difference between the "super dev mode" compile and my "normal mode" compile (yes I have the generateJsInteropExports option set)

Thanks for you help !

--
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