0

I attempt to call a javascript method from another javascript method from java method

here is my code:

public void print(){
    Excec();
}


native String flipName(String tst) /*-{

    // ...implemented with JavaScript
    alert(tst);

}-*/;

native String Excec() /*-{

    alert("exe");
    flipName("1");
    alert("exe1");

}-*/;

when i run the application it show me an error :

Excec()([]): flipName is not defined 


com.google.gwt.dev.shell.BrowserChannelServer.invokeJavascript(BrowserChannelServer.java:249) 
com.google.gwt.dev.shell.ModuleSpaceOOPHM.doInvoke(ModuleSpaceOOPHM.java:136)
com.google.gwt.dev.shell.ModuleSpace.invokeNative(ModuleSpace.java:576) 

1 Answer 1

2

This must be done in about the same way as calling a Java method from within a JSNI method.

You must specify the fully qualified name of the method you wish to call, and you also have to specify the type of the argument.

More information can be found here : http://www.gwtproject.org/doc/latest/DevGuideCodingBasicsJSNI.html

In practice this will work (replace be.knarf.gwt.client.Example with the correct package name and class name of your class) :

private native void flipName(String tst)
/*-{
   alert(tst);
}-*/;

private native void excec()
/*-{
   alert("exe");
   [email protected]::flipName(Ljava/lang/String;)("hi");
   alert("exe1");
}-*/;
Sign up to request clarification or add additional context in comments.

1 Comment

Since GWT 2.7 JSNI code may be simplified. this.@Example::flipName(*)("hi"); instead of [email protected]::flipName(Ljava/lang/String;)("hi");

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.