【问题标题】:<p:filedownload> does not download the file<p:filedownload> 不下载文件
【发布时间】:2014-01-02 21:04:54
【问题描述】:

我正在尝试使用 primefaces filedownload 下载文件(将它们发送到浏览器)。由于某种原因,它不会将文件发送到浏览器。单击页面上的按钮时,会显示我正在使用 p:filedownload 的弹出对话框。我已经看到了:p:fileDownload bean method is invoked but file download does not show up 但问题是当用户选择要下载的文件名时,我需要通过调用操作来在 bean 中设置文件:

test.xhtml

<p:dialog>
    <p:dataTable var="currentAttachment" value="#{managerBean.attachmentsForPatient()}">
      <p:column>
        <p:commandLink value="#{currentAttachment.name}"  action="#{managerBean.downloadAttachment(currentAttachment)}">
          <p:fileDownload value="#{managerBean.file}" />  
        </p:commandLink>
      </p:column>
    </p:dataTable>
</p:dialog>

ma​​nagerBean.java

public void downloadAttachment(Attachment attachment) throws IOException {
    InputStream stream = ((ServletContext)FacesContext.getCurrentInstance().getExternalContext().getContext()).getResourceAsStream(attachment.getContent().toString());  
    setFile(new DefaultStreamedContent(stream)); 
}

【问题讨论】:

    标签: jsf-2 primefaces download


    【解决方案1】:

    请检查您的 web.xml 以了解正确的配置。 示例张贴在这里..

    <filter>
        <filter-name>PrimeFaces FileUpload Filter</filter-name>
        <filter-class>org.primefaces.webapp.filter.FileUploadFilter</filter-class>
    </filter>
    <filter-mapping>
        <filter-name>PrimeFaces FileUpload Filter</filter-name>
        <servlet-name>Faces Servlet</servlet-name>
    </filter-mapping>
    

    还要检查是否添加了以下依赖项

    commons-fileupload*.jar,commons-io*.jar

    这应该会有所帮助。

    【讨论】:

    • 您将“下载”与“上传”混淆了。为什么这个答案被接受完全超出了我的理解。
    猜你喜欢
    • 1970-01-01
    • 2021-07-03
    • 2012-12-31
    • 1970-01-01
    • 2012-07-24
    • 1970-01-01
    • 2016-04-24
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多