简体   繁体   中英

How to set file limit for FileUpload in Java

I am using Primefaces' FileUpload. Can't figure out how to set FileLimit property from Java. There are no setFileLimit function, but in xhtml this property is accessible ( Primefaces Upload Example )

FileUpload filenameCreateInput = (FileUpload)
   application.createComponent(FileUpload.COMPONENT_TYPE);
...
//filenameCreateInput.setFileLimit(3);

In my application I bind those limitations with the properties of a back-end bean, but I'm not sure if there is other way to do it.

<p:fileUpload fileUploadListener="#{bean.handleFileUpload}" mode="advanced" dragDropSupport="false"  
                  multiple="true" update="messages" sizeLimit="#{bean.sizeLimit}" fileLimit="#{bean.fileLimit}" />

In your java bean:

private final Integer sizeLimit = 100000;
private final Integer fileLimit = 3;

... and their getters

The show case is based on version 4.0 of Primefaces.
According to the Primefaces documentation for version 3.4 there is no setFileLimit method for FileUpload . It does not exist in the tag documentation as well.
It looks like it is available since version 4.0 of the API .

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM