Groups keyboard shortcuts have been updated
Dismiss
See shortcuts

Re: JsInterop implementation issue

62 views
Skip to first unread message
Message has been deleted
Message has been deleted

Jens

unread,
Aug 22, 2024, 6:06:35 PM8/22/24
to GWT Users
getOrCreateJsObj() needs to return a class or interface annotated with @JsType(isNative = true). That class or interface should have a method addListener(String, fn) so you can call it in Java directly.

Corbett Tek schrieb am Donnerstag, 22. August 2024 um 15:57:31 UTC+2:
When transporting some of my previously jsni written code to jsinterop framework,  I am facing problems when accessing java methods from javascript file. 

For example in this jsni code I am accessing java method getOrCreateJsObj() and I need to convert this jsni code to jsinterop framework. How can I do this? What is the syntax for this? I tried official docs way, but it didn't worked out. Please help...

//the jsni method that I need to convert into jsinterop
private native void addWidgetListener(String event, JavaScriptObject fn) /*-{
        var component = this.@org.lib.client.widgets.Component::getOrCreateJsObj()();
        component.addListener(event, fn);
    }-*/;

public JavaScriptObject getOrCreateJsObj() {
        JavaScriptObject jsObj = getComponentJS(id);
        if (jsObj != null) {
            return jsObj;
        } else {
            return create(config);
        }
    }
Reply all
Reply to author
Forward
0 new messages