无法在 Primefaces 中正确显示 pdf 文件名

Could not show pdf file name correctly in Primefaces

我正在开发 jsf 页面并使用 primefaces。执行此 pdf 名称时显示 "dynamiccontent.properties.xhtml"。我想显示带有 pdf 名称的 pdf。我该怎么办?

<p:dialog header="Dialog" widgetVar="dialogView" modal="false">
                <h:form id="form">
                    <h:panelGrid columns="1" cellpadding="5">
                        <p:media value="#{bean.streamedContent}"
                            player="pdf" width="1000px" height="750px">
                            <f:param name="bean.selectedFile.fileName"
                                value="#{bean.generateRandomIdForNotCaching()}" />
                        </p:media>
                    </h:panelGrid>
                </h:form>
            </p:dialog>

这是我的代码;

public void showFile() {
        setStreamedContent(new DefaultStreamedContent(getData(selectedFile.getFileName()), "application/pdf",
                "downloaded_" + selectedFile.getFileName()));
    }

    private InputStream getData(String fileName) {
        File folder = new File(folderFile);
        File file = new File(folder + "\" + fileName);

        InputStream fileView = null;
        try {
            fileView = new FileInputStream(file);
        } catch (FileNotFoundException e) {
            e.printStackTrace();
        }
        return fileView;
    }

    public String generateRandomIdForNotCaching() {
        return java.util.UUID.randomUUID().toString();
    }

您可以随时尝试 PrimeFaces Extensions Document Viewer,它可以让您更好地控制如何加载 PDF 并控制流式内容的下载文件名。

download =If streamed content this will be the name of the download file. NOTE: Must end in .pdf for PDF.js to pick it up!

Link: PrimeFaces Extensions Document Viewer