[英]vaadin javascript
I am trying to integrate some js project into my vaadin app. 我正在尝试将一些js项目集成到我的vaadin应用程序中。 And I tried the methods to invoke external javascript code, only successed on some easy/javascript.
我尝试了调用外部JavaScript代码的方法,只在一些简单的/ javascript上成功。 I tried the NativeJs lib and the code is:
我尝试了NativeJs lib,代码是:
NativeJS nativeJScomponent = new NativeJS();
nativeJScomponent.setJavascript("alert('foo');");
nativeJScomponent.execute();
addComponent(nativeJScomponent);
However, when I used some other code like: 但是,当我使用其他一些代码时:
String jsCode = "<div /><script type=\"text/javascript\">var d = new Date();"
+ "var time = d.getHours();"
+ "if (time < 10) {document.write(\"<b>Good morning</b>\");}</script>";
NativeJS nativeJScomponent = new NativeJS();
nativeJScomponent.setJavascript(jsCode);
nativeJScomponent.execute();
addComponent(nativeJScomponent);
It failed to display content. 它无法显示内容。
And I also used the customelayout and label to run javascript. 我还使用了customelayout和标签来运行javascript。 The same results came.
结果相同。
Is there any method to integrate vaadin with js? 是否有任何方法将vaadin与js集成?
Window window = new Window("");
window.executeJavascript("javascript:testFunctionCall();");
The correct way to do this is to implement AbstractJavaScriptComponent
. 执行此操作的正确方法是实现
AbstractJavaScriptComponent
。 This allows you to include a plain Javascript file in your project and control that library from the server side through RPC calls and shared state. 这允许您在项目中包含一个普通的Javascript文件,并通过RPC调用和共享状态从服务器端控制该库。
An easy tutorial can be found here and the Book of Vaadin goes more in-depth here . 一个简单的教程,可以发现这里和Vaadin的书去更深入这里 。 You can also take a look at the source code of my Vaadin addon which integrates a Javascript media library with Vaadin.
您还可以查看我的Vaadin插件的源代码,它将Javascript媒体库与Vaadin集成在一起。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.