Hi,
I am facing issue in integrating javascript in vaadin application.
Issue
: If both (java class file and javascript file) are located under same directory code works fine.
However if java class file and javascript file are located in different folder; javascript file not getting picked-up with relative path. Following is the example code:
File locations:
\src\com\DemoUI.java
\src\resources\example.js
DemoUI.java
package com;
import com.vaadin.annotations.JavaScript;
import com.vaadin.annotations.Theme;
import com.vaadin.server.Page;
import com.vaadin.server.VaadinRequest;
import com.vaadin.ui.Button;
import com.vaadin.ui.Button.ClickEvent;
import com.vaadin.ui.UI;
import com.vaadin.ui.VerticalLayout;
@SuppressWarnings("serial")
@Theme("demo")
@JavaScript(value = { "../resources/example.js" })
public class DemoUI extends UI {
@Override
protected void init(VaadinRequest request) {
final VerticalLayout vLayout = new VerticalLayout();
vLayout.setMargin(true);
setContent(vLayout);
Button button = new Button("Click Me");
button.addClickListener(new Button.ClickListener() {
public void buttonClick(ClickEvent event) {
Page.getCurrent().getJavaScript().execute("showmessage('" + this.getClass().toString() + "')");
}
});
vLayout.addComponent(button);
}
}
example.js
/**
*
*/
function showmessage(source)
{
alert("This is a alert from "+source);
}
Regards,
Kunal Patil