我想从数据库中检索文件并在primefaces datatable中显示。我使用以下代码:
public StreamedContent getInputFileStreamedContent() {
if (this.document == null){
this.document = new byte[0];
}
InputStream inputStream = new ByteArrayInputStream(this.document);
return new DefaultStreamedContent(inputStream);
}
}
但是当我点击命令链接时,它会返回null。
Xhtml代码:
<p:column >
<f:facet name="header">
<h:outputText value="docId" />
</f:facet>
<h:commandLink value="#{o.userId}" rendered="#{o.inputFileStreamedContent != null}">
<p:fileDownload value="#{o.inputFileStreamedContent}"></p:fileDownload>
</h:commandLink>
</p:column>
答案 0 :(得分:0)
我找到了一个解决方案,如果有人有我的问题,我会把文件内容类型和文件名添加到DefaultSteamContent.So我的新代码:
public StreamedContent getInputFileStreamedContent() {
if (this.document == null) {
this.document = new byte[0];
}
InputStream inputStream = new ByteArrayInputStream(this.document);
return new DefaultStreamedContent(inputStream,this.fileContentType.toString(), this.fileName);
}