将 FileDownloader 与 Combobox 结合使用 [英] Using the FileDownloader with Combobox

查看:41
本文介绍了将 FileDownloader 与 Combobox 结合使用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已经尝试在 Vaadin7 中使用新的 FileDownloader.不幸的是,它需要一个用于扩展"组件的 AbstractComponent(它监听点击)

I've tried using the new FileDownloader in Vaadin7. Unfortunately, it needs an AbstractComponent for the "extend" component (where it listens for the clicks)

有没有办法将它与组合框项目一起使用?因为它们不是抽象组件,因此不适合扩展"方法.

Is there a way to use it with combobox items? As they are not AbstractComponents and thus do not fit with the "extend" method.

推荐答案

这是我的解决方法.它对我来说就像一种魅力.希望它会帮助你.此示例针对 MenuItem,但您可以针对 ComboBox 进行修改.

Here is my work-around. It works like a charm for me. Hope it will help you. This example is for the MenuItem, but you can modify for ComboBox.

  1. 创建一个按钮并通过 Css 隐藏它(不是通过代码:button.setInvisible(false))

  1. Create a button and hide it by Css (NOT by code: button.setInvisible(false))

final Button downloadInvisibleButton = new Button();
downloadInvisibleButton.setId("DownloadButtonId");
downloadInvisibleButton.addStyleName("InvisibleButton");

在您的主题中,添加此规则以隐藏 downloadInvisibleButton:

In your theme, add this rule to hide the downloadInvisibleButton:

.InvisibleButton {
    display: none;
}

  • 当用户点击menuItem时:将fileDownloader扩展到downloadInvisibleButton,然后通过JavaScript模拟点击downloadInvisibleButton.

  • When the user clicks on menuItem: extend the fileDownloader to the downloadInvisibleButton, then simulate the click on the downloadInvisibleButton by JavaScript.

    menuBar.addItem("Download", new MenuBar.Command() {
      @Override
      public void menuSelected(MenuBar.MenuItem selectedItem) {
        FileDownloader fileDownloader = new FileDownloader(...);
        fileDownloader.extend(downloadInvisibleButton);
        //Simulate the click on downloadInvisibleButton by JavaScript
        Page.getCurrent().getJavaScript()
           .execute("document.getElementById('DownloadButtonId').click();");
      }
    });
    

  • 这篇关于将 FileDownloader 与 Combobox 结合使用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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