【发布时间】: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>
managerBean.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