Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

PrimeFaces fileUpload showing the file name after upload

I want to show the uploaded file below the fileUpload component after uploading the file. As default it just shows the file when i choose it but after i press upload button file name disappears. I checked all the attributes of the fileUpload tag but couldn't find anything related to it.

edit: Thanks Daniel, your solution works well, but you know the outputText is an external text under the fileUploader i would like to know if primeFaces has a solution to show the file when it is uploaded as it shows after choosing file like the picture below i want to see the file name also after uploading like this:

enter image description here

like image 590
Bilâl Yüksel Avatar asked Jun 27 '13 09:06

Bilâl Yüksel


1 Answers

Just place a <h:outputText and fill it with the file name from your bean after the and update it with your p:fileUpload

like this

<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>                                   

Inside your bean:

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

Also take a look at the following BalusC answer: event.getFile().getFileName() is returning filename with complete path in JSF2.0 with PrimeFaces 3.5

like image 158
Daniel Avatar answered Oct 24 '22 19:10

Daniel