简体   繁体   English

Gwt中的Javascript库

[英]Javascript library in gwt

How to aadd javscript library from file to gwt? 如何将javscript库从文件添加到gwt?

I tried: 我试过了:

  • ScriptInjector - exception is thrown: onModuleLoad() threw an exception ScriptInjector引发异常: onModuleLoad()引发了异常

    Exception while loading module modue.name. 加载模块modue.name时发生异常。 See Development Mode for details. 有关详细信息,请参见开发模式。 java.lang.reflect.InvocationTargetException at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57) at ... java.lang.reflect.InvocationTargetException(sun.reflect.NativeMethodAccessorImpl.invoke0(本机方法)at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)...

  • own script injector ( source ) 自己的脚本注入器(

    Problem: content of the library is added to the source code, but cannot be accessible any part of the source code. 问题:库的内容已添加到源代码中,但是无法访问源代码的任何部分。

Can sb give an example? 可以给个例子吗?

Solution for your problem with the 2nd option (own script injector) 第二个选项(自己的脚本注入器)的问题解决方案

Problem: content of the library is added to the source code, but cannot be accessible any part of the source code. 问题:库的内容已添加到源代码中,但是无法访问源代码的任何部分。

You have to use JSNI to be able to use the javascript-methods of the added library in gwt. 您必须使用JSNI才能使用gwt中添加的库的javascript方法。

Here is a little example for executing a javascript-method from java: 这是一个从Java执行javascript方法的小例子:

Let's say the added javascript-library contains this method: 假设添加的javascript-library包含此方法:

function say(message) {
    window.alert(message);
}

Create a java class JavascriptLibrary.java: 创建一个Java类JavascriptLibrary.java:

public final class JavascriptLibrary {

    public static native void sayJava(String message) /*-{
        $wnd.say(message);
    }-*/;

}

Now you can execute this method with JavascriptLibrary.sayJava("Hello"); 现在,您可以使用JavascriptLibrary.sayJava("Hello");执行此方法JavascriptLibrary.sayJava("Hello");

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

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