1

Im building a web application with GWT and I want to give users the ability to extend its functionality by some sort of Javascript API that would interact with the app core written in GWT. Basically, this JS API would map to some of my GWT internal methods that would do the actual job.

So, to achieve this, i read on GWT JSNI official documentation a trick that consists in creating a global JS variable from GWT and assigning it a call to the actual GWT method. Then i would make the call in my handwritten JS code through this variable.

Unfortunately I couldnt make it to work (the example contained syntax errors son im not sure that it has even been tested). Doing more research, i found on this site a similar solution that assigns the JS var an anonymous function that makes the call. It looks like this:

/*GWT code that assigns the anonymous function*/

private static native void loadWrapper() /*-{
    $wnd.showMessage =
        $entry(@com.Glob3Mobile.client.TestApi::msgBox());
}-*/;

public static void msgBox() {
    Window.alert("hello");
}

This solution looks promising but I havent been able to make it to work. When i do "window.showMessage();" in my handwritten JS code it wont work. I have found these issues:

  • window.showMessage seems to be created but JS console says that its not a function, even though i inspected the dom tree and verified that the variable does contains a function.
  • It seems like I always have to append the "window." preffix, since the var is being created within the window object. This is a considerably concerning issue, cause forcing users to write like this every time they want to call a function is really tedious.

If anybody knows the solution to these issues (or an alternative approach to achieve what im trying to do), id be very grateful to hear. Thanks in advance.

1 Answer 1

1

You need to do some extra work. Because the method you described works only at compile time. After compilation the GWT method names are gone, because they are obfuscated. But there is a library that can help you with this: gwt-exporter

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.