0

I've read the other posts regarding this topic already. I just want to clarify, is there really no way in vaadin to:

  • Create a custom layout html file, like custom.html;
  • Import a java script file to it, then...;
  • Call the js functions from within the html file, like one would normally?

Currently I have home.html in my Vaadin\themes(project)\layouts and a javascript library in Vaadin\js\custom.js. In my Panel class i have annotation @JavaScript({"vaadin://js/custom.js"}), and in my html i tried <script type="text/javascript" src="custom.js"></script>.

I have in the html file some hyperlinks, that need to call the js functions when clicked.

Any info if this is possible, would be most helpful?

user1479897
  • 145
  • 2
  • 11

1 Answers1

1

Its not possible to call it directly from your html layout. Notice that your custom html file its only a layout thus Vaadin generates his own html using your layout AND server side code. Thats why your <script> annotation is not only redundant - it is simply useless.

However its still possible to call JavaScript using Vaadin. Using listeners you can call client-side code from the server:

ok.addClickListener(new ClickListener()
{
    @Override
    public void buttonClick(ClickEvent event)
    {
        JavaScript.getCurrent().execute("itsHot()");
    }
});
kukis
  • 4,489
  • 6
  • 27
  • 50
  • Ok I had seen an example of using JavaScript.getCurrent().execute(""), but was hoping there was a way to create the html rather than have it generated. But thanks for the info, it makes sense now. – user1479897 May 19 '15 at 06:50
  • Note that if you are using @PreserveOnRefresh annotation in your UI class, then these JavaScript.getCurrent().execute(..) commands might not be executed on refresh. In the case of a click listener executing it it shouldn't be a problem though. – Niklas May 20 '15 at 06:57