我用这个参数设置我的 FileUpload 组件:
<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"/>
但如果我选择更多图片,我不会收到任何错误或警告。
最佳答案
我重现了相同的行为,但我认为这不是故意的。如果您使用 auto="true"
,您可以做一些变通,因为文件会立即上传。另一方面,您可以确保您的支持 bean 正在处理上传的最后 文件(也许用户首先选择了错误的文件并想使用另一个文件?)。
fileLimit="1"
仅在使用 mode="advanced"
和 multiple="true"
时限制文件限制(参见 [ 1]),但目前 primefaces 不支持(参见 [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在第 218 页
关于file-upload - Fileupload Primefaces 中的最大文件数,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10693588/