Calling Javascript Function

I’ve read the documents at but I am still having problems getting a simple test case running.

I want to call a javascript function after a vaadin button is pressed. For simplicity, i have a bar.js that looks like

window.com_foo_bar_Bar = function() {
    function test() {
    	alert("test called");

I then created a java file

@JavaScript({ "bar.js"})
public class Bar extends AbstractJavaScriptExtension  {
	private static final Logger log = Logger.getLogger(Bar.class);
        protected Class<? extends ClientConnector> getSupportedParentType() {
              return UI.class;
  	public void testIt() {"DownloadFile");

The javascript file and the java class are in the same package.

Now to run it, on a button handler I have:

private void onClick() {"Button Clicked");
		 Bar bar= new Bar();

I would expect after clicking my button to get an alert from the javascript, but I see the log messages, but no alerts.

I am sure I am doing something stupid. Can you point me in the right direction? All the examples I see online have the javascript returning a UI component.


I got it to work when I call extend(UI).

can you give me a code snippet of what you correct with that made it work?

hi dustin hunter,

i want to call a js funtion on button click but i can’t do.

how did you do it, could you explain please? i need to your suggestion.

thanks a lot.

just with java no script :slight_smile:

Robot robot = Robot();