Reputation: 44
I'm attempting to run a native Java function off of a JSNI call in my GWT app. It looks something like this:
package foo.client;
public class AAA implements EntryPoint, UIupdate {
public native void initChangeFunc() /*-{
$wnd.jsChangeView = function () {
[email protected]::changeToHistory();
alert("got here");
};
}-*/;
public void changeToHistory() {
Window.alert("Hello World");
//Change view here.
this.changeView("history");
this.changeHistoryView("bydate");
};
...
public void onModuleLoad() {
...
this.initChangeFunc();
}
}
Attaching the jsChangeView() function call to a link onclick() in the front-end and clicking it results in a "got here" alert, but not a "Hello World" alert, and the other two functions aren't running either. GWT isn't my area of expertise, and this isn't my app, so I know I'm missing something basic here. Any takers?
Upvotes: 1
Views: 816
Reputation: 64561
[email protected]::changeToHistory()
is only referencing the method (a "function pointer" if you like, or, in JavaScript, just a "function"), it doesn't call it. You have to write [email protected]::changeToHistory()()
to actually make the call.
It's more obvious when the method has arguments, e.g.: [email protected]::changeToHistory(Ljava/lang/String;I)
vs. [email protected]::changeToHistory(Ljava/lang/String;I)("foo", 3)
.
Upvotes: 3