Answer the question
In order to leave comments, you need to log in
How to solve JSNI issue in GWT?
There are 2 modules: GWT and Java(Spring);
Project
--GWT
--Java
I'm trying to call a method from a java module:
public class MyClass extends Composite{
@UiField
TextBox text;
@UiField
Button btn;
interface EmailMailingUiBinder extends UiBinder<HTMLPanel, MyClass> {
}
private static MyClassUiBinder myUiBinder = GWT.create(MyClassUiBinder.class);
public MyClass() {
HTMLPanel rootElement = ourUiBinder.createAndBindUi(this);
initWidget(rootElement);
/* do smth and @return param. Login, for example */
/* Вешаю обработчик на кнопку btn*/
btn.addClickHandler( (event) -> {
/* вот здесь мне нужно вызвать метод, при нажатие на эту самую кнопку, из модуля Java
но так, как в GWT(JS) нельзя это сделать использую JSNI метод(собственно не уверен, что правильно его использую)
*/
sendOnClick(login); //native метод описан ниже
});
}
/*
в таком виде этот native метод при сборки Gradle выдает Missing qualifier on instance method на строке N1
*/
public native void sendOnClick(String login) /*-{
/*строка N*/ @ru.my.java.packet.proj.SendingService::sendIt(Ljava/lang/String;)(login);
}-*/;
}
Answer the question
In order to leave comments, you need to log in
JSNI, in the form in which you want to use it, is designed to call some static method from Java from Javascript, and on the client side, i.e. parts of the GWT application. This is done by mapping a java method to a javascript function, like so:
public static native void prepareJSNI() /*-{
var frame = $wnd.frames["sliderFrame"];
frame.contentWindow.refreshTest = @com.mmk.sniper.client.FirstPanel::refreshTest(Ljava/lang/String;Ljava/lang/String;);
}-*/;
The prepareJSNI() method is called when the GWT application is initialized.
Those. first you need to map the static java method to a javascript function, and then call it from browser javascript. Again, this is about client-side code (GWT).
In your case, as far as I understand, it is necessary that the server code (spring, etc.) be executed when the button is pressed. Here, the easiest way would be to call via GWT-RPC.
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question