【问题标题】:downloaded file in primefaces datatable is nullprimefaces 数据表中下载的文件为空
【发布时间】:2016-05-22 14:01:04
【问题描述】:

我想从数据库中检索文件并显示在 primefaces 数据表中。我使用此代码:

        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>

【问题讨论】:

  • 所以你是说这在数据表之外有效?
  • 我不在数据表之外检查它

标签: jsf primefaces datatable download


【解决方案1】:

如果有人遇到我的问题,我会找到解决方案。我应该将文件内容类型和文件名添加到 DefaultSteamContent。所以我的新代码:

    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);
}

【讨论】:

    猜你喜欢
    • 2013-03-25
    • 1970-01-01
    • 1970-01-01
    • 2017-11-15
    • 2017-11-21
    • 1970-01-01
    • 1970-01-01
    • 2015-11-18
    • 2012-05-18
    相关资源
    最近更新 更多