Vaadin Adding Javascript to Custom Layout

柔情痞子 提交于 2019-12-12 06:15:28

问题


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?


回答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()");
    }
});


来源:https://stackoverflow.com/questions/30307205/vaadin-adding-javascript-to-custom-layout

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!