Pages

Sunday, November 08, 2009

/*- JSNI in GWT -*/

We all know about JNI. It is a feature of JAVA. With this you communicate with other codes, DLLs written not in JAVA. This is an unique feature of JAVA. Because lots of code has already been written in many other languages before JAVA hit the market. So just no need to rewrite all those in JAVA again. So these are also true for GWT. Tons of Java scripts are already available in the web. Should we rewrite all of them. GWT's answer is no. Use JSNI. Java Script Native Interface. Its simple just like JNI. Declare a native method

public native void myJSNI(String message)


in case of JAVA the method body would be in another file in another languag
e. But whats here. No you need not to look for a new file again. You will write the Javascript code here in the same file just like another JAVA method's body. But specialty is the method body should be commented specially

 So this good looking method body will not work here

public native void myJSNI(String message)
    /*-{
        //Javascript Code
        window.alert(message);
    }-*/;
So the here the method body is specially commented with  /*-   -*/


No comments:

Post a Comment