I am quite unsure what you mean by html script. If it is something you can achieve using JavaScript then here is my try.
Generally to execute JavaScript on button click
Button js = new Button("Do JavaScript");
js.addClickListener( click -> {
com.vaadin.ui.JavaScript.getCurrent().execute("alert(´Hello´)");
});
When in need to use external .js
files, for example hello.js
, contents below
function hello() {
alert("Hello JavaScriptWorld!");
}
Assuming hello.js
is directly under /VAADIN/
directory, add following annotation to your UI
or relevant component class
@JavaScript({"vaadin://hello.js"}) // all paths must be relative to /VAADIN
Then in ClickListener
you can refer to function hello()
like
com.vaadin.ui.JavaScript.getCurrent().execute("hello()");