Search code examples
file-uploadjsf-2primefaces

Max number of file in Fileupload Primefaces


I set my FileUpload component with this params:

 <p:fileUpload label="Select image"  
                    mode="advanced"  
                    update="messages"  
                    fileUploadListener="#{fileUploadController.handleFileUpload}"
                    sizeLimit="1000000"   
                    fileLimit="1"
                    fileLimitMessage="Only 1 image"
                    allowTypes="/(\.|\/)(gif|jpe?g|png)$/"/> 

  <p:growl id="messages" showDetail="true"/>  

But if i select more image i don't get any error or warning.


Solution

  • I reproduced the same behavior, but I dont think it's intentional. You can do a little workaround if you use auto="true" because the file will be uploaded immediately. On the other hand you can make sure that your backing bean is just processing the last file uploaded (maybe the user selected a wrong file in the first place and wants to use another one?).

    fileLimit="1" only limits the file limit when using mode="advanced" and multiple="true" (see [1]), but that is currently not supported by primefaces (see [2]).

    [1] http://forum.primefaces.org/viewtopic.php?f=3&t=14194

    [2] https://www.primefaces.org/docs/guide/primefaces_user_guide_6_1.pdf at page 218