Hello. Can you please clarify? What actually are you trying to do?
--
You received this message because you are subscribed to the Google Groups "TeaVM" group.
To unsubscribe from this group and stop receiving emails from it, send an email to teavm+un...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/teavm/9b0a21cd-9fd6-4fcf-868d-a72c786d705an%40googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/teavm/276d6ff3-803d-409c-89de-b721cf78f7ben%40googlegroups.com.
/**
* Bridges calls from javascript to the widget
*/
class Bridge implements JSObject {
@JSProperty
public void loadRosette(String id) {
try {
RosetteWidget.this.retrieveRosette(Long.parseLong(id));
} catch (NumberFormatException e) {
if (Client.isLoggable(Level.WARNING)) {
LOG.warning("Invalid id. Can't load rosette");
}
}
}
@JSBody(script = "window.widgetBridge = this;")
public static native void exposeToJavaScript();
}
@JSBody(params= "id", script = "return javaMethods.get('org.zfcj.rosettes.client.RosetteWidget.loadRosette(Ljava/lang/String;)V;').invoke(widget, id);")
public static native void loadRosette(String id);
Can anyone help?
Sorry to bump this thread but I'm having similar problems. Its not clear to me how I can structure my code so that I can call a method in my java widget from a javascript function. My widget does not meet the criteria of JSObject so I'm trying an inner class./**
* Bridges calls from javascript to the widget
*/
class Bridge implements JSObject {
@JSProperty
public void loadRosette(String id) {
try {
RosetteWidget.this.retrieveRosette(Long.parseLong(id));
} catch (NumberFormatException e) {
if (Client.isLoggable(Level.WARNING)) {
LOG.warning("Invalid id. Can't load rosette");
}
}
}
@JSBody(script = "window.widgetBridge = this;")
public static native void exposeToJavaScript();
}
This compiles. I try window.widgetBridge.loadRosette("2934") in javascript some time after the page and widget have loaded. It errors because window.widgetBridge is null. I instantiate a Bridge at the end of the widget's init routine (called from main) and call exposeToJavaScript() there. Am I supposed to call that myself?
I also tried to add a JSBody method to the Client (main) class, like James but its not working for me.@JSBody(params= "id", script = "return javaMethods.get('org.zfcj.rosettes.client.RosetteWidget.loadRosette(Ljava/lang/String;)V;').invoke(widget, id);")
public static native void loadRosette(String id);
where widget is a static field initialized in main(). I suspect this is incorrect usage. It errors with[ERROR] Can't call method org.zfcj.rosettes.client.RosetteWidget.loadRosette(Ljava/lang/String;)V of non-JS class