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

无法在Primefaces中正确显示pdf文件名,pdf,jsf,primefaces,Pdf,Jsf,Primefaces,我正在开发jsf页面并使用primefaces。执行此操作时,pdf名称将显示“dynamiccontent.properties.xhtml”。我想展示带有pdf名称的pdf。我该怎么办 <p:dialog header="Dialog" widgetVar="dialogView" modal="false"> <h:form id="form"> <h:panelGrid columns=

我正在开发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>

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

下载=如果是流式内容,则这将是下载的名称 文件注意:pdf.js必须以.pdf结尾才能获取它


链接:

@Kukeltje我无法在“搜索引擎”上找到任何解决方案。有一种东西叫做“大脑”,有时有些人不使用它。试着使用它?我也尝试了第二个答案的解决方案,但不起作用。如果我是你,我不会删除上面的粗鲁评论。我知道别担心,但是你可以花更多的时间和他们在一起。我的评论并不粗鲁,因为你没有读到这篇文章,所以你就这样解释了。我只能在问题上花费一定的时间,而那些不好的问题(表现得很少努力)并不总能得到他们想要的关注。祝你好运(值得注意的是,我的另一条评论被删除了,而不是被我删除了)你的评论是粗鲁的,所以被编辑删除了。我也祝你好运。非常感谢你,先生。
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();
    }