Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Vaadin 7 : How to import JS files from custom path?

Tags:

vaadin

vaadin7

I am using Vaadin-7 and this answer was not fix for me .

I am trying to import my js file under myproject/WebContent/js/test.js . I used @JavaScript in my UI class as below..

@Theme("myTheme")
@SuppressWarnings("serial")
@Title("VaadinTest")
@JavaScript("js/test.js")
public class VaadinTest extends UI {

@Override
protected void init(VaadinRequest request) {
    final VerticalLayout layout = new VerticalLayout();
    layout.setMargin(true);
    setContent(layout);
}
}

But I got "NetworkError: 404 Not Found - http://localhost:8080/myproject/APP/PUBLISHED/js/test.js" error log in my firebug console.

So , how can I import js files from my custom directories ?

PS: Please don't be force me to create APP/PUBLISHED/ directory manually ! Thanks.

like image 805
Cataclysm Avatar asked Jul 16 '14 08:07

Cataclysm


2 Answers

You can use app://:

@JavaScript({ "app://js/test.js" })

or use:

@JavaScript({ "vaadin://js/test.js" })

Generated url inside VAADIN folder:

http://localhost:8080/myproject/VAADIN/js/test.js
like image 145
Zigac Avatar answered Jan 04 '23 21:01

Zigac


the file you refer to must be reachable by the classloader relative to the package you are using it in. according to your example, lets say your package of VaadinTest is com.example.app and you want to access it as js/test.js you have to put it in the directory com/example/app/js/test.js in a "root" for the classloader to find it (e.g. src/main/java,groovy or where resources are loaded from in your config).

like image 20
cfrick Avatar answered Jan 04 '23 19:01

cfrick