javascript integration issue

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

Hello.

I think once i have the same problem, but i don’t remember how i solve it.

Now i’m using this:

@Override
public void sessionInit(SessionInitEvent event) {
event.getSession().addBootstrapListener(new BootstrapListener() {

private static final long serialVersionUID = 1L;

  @Override
  public void modifyBootstrapPage(BootstrapPageResponse response) {
   for (Element scriptElement : getScriptElements()) {
     response.getDocument().getElementsByTag("head").first().appendChild(scriptElement);
    }
  }

  @Override
  public void modifyBootstrapFragment(BootstrapFragmentResponse response) { }
});
}

@SuppressWarnings("static-method")
    private List<Element> getScriptElements() {
        List<Element> list = new ArrayList<Element>();

        Attributes attributes = new Attributes();
        Element scriptElement = null;

        attributes = new Attributes();
        attributes.put("type", "text/javascript");
        attributes.put("src", "./VAADIN/themes/vaadingwt/javascript/customize.js");
        scriptElement = new Element(Tag.valueOf("script"), "", attributes);
        list.add(scriptElement);
...

This modify header and include javascript tags.

Hi Kunal,

I have the same problem. Did you manage to find a solution?

did anyone found a resolution to this problem yet? (aside from modifying the bootstraping page)