M1M6
M1M6

Reputation: 1013

Call JavaScript methode from another Js in GWT

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) 

Upvotes: 0

Views: 72

Answers (1)

Knarf
Knarf

Reputation: 2156

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");
}-*/;

Upvotes: 2

Related Questions