Question: I am trying to integrate some js project into my vaadin app. And I tried the methods to invoke external javascript code, only successed on some easy/javascript.
I tried the NativeJs lib 
and the code is:

```
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. The same results came. 

Is there any method to integrate vaadin with js?

Answer: 
```
Window window = new Window("");
window.executeJavascript("javascript:testFunctionCall();");

```
The correct way to do this is to implement `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.

An easy tutorial can be found [here](https://vaadin.com/blog/-/blogs/vaadin-7-loves-javascript-components) and the Book of Vaadin goes more in-depth [here](https://vaadin.com/book/-/page/gwt.javascript.html). You can also take a look at the source code of my [Vaadin addon](https://github.com/bdunn44/MEJS-Vaadin) which integrates a Javascript media library with Vaadin.