【问题标题】:PrimeFaces fileUpload showing the file name after uploadPrimeFaces fileUpload 显示上传后的文件名
【发布时间】:2013-06-27 09:17:32
【问题描述】:

我想在上传文件后在 fileUpload 组件下方显示上传的文件。默认情况下,它只在我选择它时显示文件,但在我按下上传按钮后文件名消失。我检查了 fileUpload 标记的所有属性,但找不到任何相关内容。

编辑:谢谢 Daniel,您的解决方案运行良好,但您知道 outputText 是 fileUploader 下的外部文本下面的图片我想在上传后也看到文件名:

【问题讨论】:

    标签: jsf file-upload primefaces


    【解决方案1】:

    只需放置一个<h:outputText 并在之后用你的bean 中的文件名填充它,然后用你的p:fileUpload 更新它

    喜欢这个

    <h:form prependId="false" enctype="multipart/form-data">
        <p:fileUpload update="@form" mode="advanced" auto="true" 
            fileUploadListener="#{myBean.myFileUpload}"/>
        <h:outputText value="#{myBean.myFileName}"/>    
    </h:form>                                   
    

    在你的 bean 中:

    public void myFileUpload(FileUploadEvent event) {
        myFileName = FilenameUtils.getName(event.getFile().getFileName());
    }
    

    还请查看以下 BalusC 答案:event.getFile().getFileName() is returning filename with complete path in JSF2.0 with PrimeFaces 3.5

    【讨论】:

    猜你喜欢
    • 2013-03-10
    • 2013-06-06
    • 1970-01-01
    • 2013-12-16
    • 2012-04-27
    • 1970-01-01
    • 1970-01-01
    • 2023-03-19
    • 1970-01-01
    相关资源
    最近更新 更多