Vaadin 将 Javascript 添加到自定义布局 [英] Vaadin Adding Javascript to Custom Layout

查看:30
本文介绍了Vaadin 将 Javascript 添加到自定义布局的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已经阅读了有关此主题的其他帖子.我只是想澄清一下,vaadin 真的没有办法:

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

  • 创建一个自定义布局的html文件,比如custom.html;
  • 导入一个java脚本文件,然后...;
  • 从 html 文件中调用 js 函数,就像通常那样?

目前我在 Vaadin\themes(project)\layouts 中有 home.html,在 Vaadin\js\custom.js 中有一个 javascript 库.在我的 Panel 类中,我有注释 @JavaScript({"vaadin://js/custom.js"}),而在我的 html 中,我尝试了 <script type="text/javascript" src="custom.js"></script>.

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>.

我在html文件中有一些超链接,点击时需要调用js函数.

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?

推荐答案

无法直接从 html 布局中调用它.请注意,您的自定义 html 文件只是一个布局,因此 Vaadin 使用您的布局和服务器端代码生成他自己的 html.这就是为什么您的 <script> 注释不仅是多余的 - 它根本没用.

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.

但是仍然可以使用 Vaadin 调用 JavaScript.使用侦听器,您可以从服务器调用客户端代码:

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

这篇关于Vaadin 将 Javascript 添加到自定义布局的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆