使用 ViewScoped 托管 bean 从 p:datatable 进行 p:filedownload 不起作用。它调用方法prepareFile和getFile两次。在我提到的方法的第一次调用中,它设置表中的第一个文件,在方法的第二次调用中,它设置正确的文件,但它总是只下载第一个文件,而从不下载第二个文件。
为什么会调用两次?为什么它设置表中的第一个文件?有任何想法吗?
这是我的代码:
<p:dataTable id="offer_attachment_datatable"
widgetVar="offer_attachment_datatable"
var="attachment"
value="#{offerBean.offerAttachments}">
<p:column>
<f:facet name="header"/>
<p:commandLink ajax="false" actionListener="#{offerBean.prepareFile(attachment)}" title="#{attachment.name}">
<p:graphicImage value="/resources/themes/navigator_b2e/images/drive-download.png" />
<p:fileDownload value="#{offerBean.file}"/>
</p:commandLink>
</p:column>
</p:dataTable>
在托管 bean 中(简化):
private StreamedContent file;
private InputStream stream;
public void prepareFile(OfferAttachment attachment){
System.out.println("Attachment: "+attachment.getName());
stream = new ByteArrayInputStream(attachment.getAttachment());
file = new DefaultStreamedContent(stream, "text/plain", attachment.getName());
stream = null;
}
public StreamedContent getFile() {
System.out.println("File: "+file.getName());
return file;
}
public void setFile(StreamedContent file) {
this.file = file;
}
因此,我使用简单的 p:confirmDialog 做了一个解决方法,在其中提取了有问题的 ajax=false 命令链接,因此我通过在 p:datatable 中单击附件来选择附件,然后从 p:confirmdialog 执行下载。
我在2.2.1中也遇到了同样的问题。我通过替换找到了解决方案p:commandLink
to p:commandButton
具有相同的属性。似乎这是与行为相关的错误commandLink
成分
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)