9

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

Taylan Aydinli
  • 4,333
  • 15
  • 39
  • 33
Bilâl Yüksel
  • 91
  • 1
  • 1
  • 3

1 Answers1

8

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

Community
  • 1
  • 1
Daniel
  • 36,833
  • 10
  • 119
  • 200
  • Mind to use `FilenameUtils#getName()` to bridge the security bug that some browsers incorrectly send the full client side path along the filename: http://stackoverflow.com/questions/15728320/event-getfile-getfilename-is-returning-filename-with-complete-path-in-jsf2-0/15729327#15729327 – BalusC Jun 27 '13 at 12:12