srini1998
srini1998

Reputation: 51

Issue with calling instance method from handwritten javascript

Can anyone help with what is wrong in the code below(based on the answers to a similar question asked on SO):

    public String javaMethod(String input) {
        return "it works";
}

    public native void defineBridgeMethod() /*-{ 
        var that = this;
        $wnd.jsFunction= $entry(function(msg) {
                 [email protected]::javaMethod(Ljava/lang/String;)(msg)
            });
    }-*/;

The issue is that Javascript does not find jsFunction: alert(jsFunction) in Javascript code returns 'undefined'.

Thanks.

Edit: Huh, one hour later: figured out that I just needed to have that.@com... returned!

Upvotes: 0

Views: 738

Answers (1)

srini1998
srini1998

Reputation: 51

Huh, one hour later: figured out that I just needed to have that.@com... returned!

The bridge method should be:

public native void defineBridgeMethod() /*-{ 
    var that = this;
    $wnd.jsFunction= $entry(function(msg) {
             return [email protected]::javaMethod(Ljava/lang/String;)(msg)
        });
}-*/;

Upvotes: 2

Related Questions