【问题标题】:How to download multiple files with Primefaces如何使用 Primefaces 下载多个文件
【发布时间】:2013-09-29 17:45:59
【问题描述】:

我有一个数据表,用户将从该表中选择一些文件,当他单击“下载”按钮时,他将下载这些文件。下面的代码完美运行,但有一个 InputStreamList,正如您在此处看到的那样,不仅必须下载第一个流,还必须下载其他流。有什么想法吗?

这是我的控制器方法;

StreamedContent file;

public void downloadFile(){
    InputStream stream = streamList.get(0);
    file = new DefaultStreamedContent(stream, "xml", getRandomName());
}

我的看法;

<p:commandButton value="Download"
                         ajax="false"
                         actionListener="#{myController.downloadFile()}"
                         icon="ui-icon-disk">
            <p:fileDownload value="#{myController.file}" />
        </p:commandButton>

【问题讨论】:

  • @BalusC 如何以 zip 格式提供它们?

标签: jsf primefaces


【解决方案1】:

使用 Javascript 模拟每个文件的 onClick 事件。

显示文件

 <p:commandButton  value="Download" ajax="false"  icon="ui-icon-arrowthick-1-s" styleClass="foo">
         <p:fileDownload value="#{fileDownloadView.file}" />
  </p:commandButton>

全部下载按钮

<p:commandButton value="DownloadAll" ajax="false" onclick="start()" icon="ui-icon-arrowthick-1-s"/>

Javascript

function start() {                    
                    var buttons = $(".foo");
                    $(buttons).each(function(){
                    $(this).click();
                     });             

                    }

【讨论】:

    猜你喜欢
    • 2011-10-18
    • 2015-10-31
    • 1970-01-01
    • 2019-02-03
    • 2014-04-20
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多