简体   繁体   English

如何在GWT中实现JSNI

[英]how to implement JSNI in GWT

I have experience in GWT but know nothing about JSNI or Javascript . 我有GWT的经验,但对JSNI或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. 我现在正在为JSNI搜索几天,但我无法理解如何在我的GWT项目中实现JSNI。

where and how i will add a javascript file in my GWT project, where i will write my javascript? 我将在GWT项目中添加javascript文件的位置和方式,我将在哪里编写我的javascript?

and then i want to call a javascript method from java/GWT 然后我想从java / GWT调用一个javascript方法

Here is a simple example of how to code a JSNI method that puts up a JavaScript alert dialog: 这是一个简单的示例,说明如何编写一个JSNI方法来建立一个JavaScript警报对话框:

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

but where will i add this code in my GWT project 但是我将在GWT项目中添加此代码

i hvae just created a new project "HelloJSNI" and in my class HelloJSNI.java , i added this code , am i doing write ? 我刚刚创建了一个新项目“HelloJSNI”,在我的类HelloJSNI.java中,我添加了这个代码,我在写吗?

      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(@com.jsni.client.HelloJSNI::testJSNI(IFI));

    }-*/;
}

will i be able to see "hello JSNI "? 我能看到“你好JSNI”吗? Thanks 谢谢

The first and best place to learn about JSNI is this article . 这篇文章是了解JSNI的第一个也是最好的地方。

If you have any more specific questions after reading that article, please ask here on SO. 如果您在阅读该文章后有任何更具体的问题,请在此处询问。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM