最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

javascript - how to implement JSNI in GWT - Stack Overflow

programmeradmin10浏览0评论

I have experience in GWT but know nothing about JSNI or Javascript . i am searching for few days for JSNI now but i am not able to understand how to implement JSNI in my GWT project.

where and how i will add a javascript file in my GWT project, where i will write my javascript?

and then i want to call a javascript method from java/GWT

Here is a simple example of how to code a JSNI method that puts up a JavaScript alert dialog:

          public static native void alert(String msg) /*-{
          $wnd.alert(msg);
           }-*/;

but where will i add this code in my GWT project

i hvae just created a new project "HelloJSNI" and in my class HelloJSNI.java , i added this code , am i doing write ?

      public void onModuleLoad() {
        alert("call from java to Javascript");

    }
    public void testJSNI(int amt, float interestRate,
            int term){
        Window.alert("call from javascript to java");
    }
    public static native void alert(String msg) /*-{
//    $wnd.alert(msg);
      $wnd.testJSNI=
          $entry(@.jsni.client.HelloJSNI::testJSNI(IFI));

    }-*/;
}

will i be able to see "hello JSNI "? Thanks

I have experience in GWT but know nothing about JSNI or Javascript . i am searching for few days for JSNI now but i am not able to understand how to implement JSNI in my GWT project.

where and how i will add a javascript file in my GWT project, where i will write my javascript?

and then i want to call a javascript method from java/GWT

Here is a simple example of how to code a JSNI method that puts up a JavaScript alert dialog:

          public static native void alert(String msg) /*-{
          $wnd.alert(msg);
           }-*/;

but where will i add this code in my GWT project

i hvae just created a new project "HelloJSNI" and in my class HelloJSNI.java , i added this code , am i doing write ?

      public void onModuleLoad() {
        alert("call from java to Javascript");

    }
    public void testJSNI(int amt, float interestRate,
            int term){
        Window.alert("call from javascript to java");
    }
    public static native void alert(String msg) /*-{
//    $wnd.alert(msg);
      $wnd.testJSNI=
          $entry(@.jsni.client.HelloJSNI::testJSNI(IFI));

    }-*/;
}

will i be able to see "hello JSNI "? Thanks

Share Improve this question edited Mar 11, 2012 at 20:50 user1226162 asked Mar 11, 2012 at 20:14 user1226162user1226162 2,0429 gold badges29 silver badges43 bronze badges 1
  • Could you please first understand using the Java "Native" keyword without even considering GWT. – Blessed Geek Commented Mar 12, 2012 at 0:26
Add a ment  | 

1 Answer 1

Reset to default 2

The first and best place to learn about JSNI is this article.

If you have any more specific questions after reading that article, please ask here on SO.

发布评论

评论列表(0)

  1. 暂无评论