Primefaces上传,如何在高级模式下只允许一次上传

2024-02-18

我想知道是否可以通过使用 primefaces 提前上传模式来限制用户仅上传一个文件,目前我有:

 <p:fileUpload fileUploadListener="#{fileUploadController.handleFileUpload}"
                                  mode="advanced" 
                                  multiple="false" 
                                  update="messages"
                                  sizeLimit="100000000" 
                                  allowTypes="/(\.|\/)(gif|jpe?g|png|doc|docx|txt|pdf)$/"
                                  auto="false"/>


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

如您所见,我有多个“false”,但用户仍然可以上传多个文件,有什么提示吗?

EDIT :

                <p:fileUpload widgetVar="upload" fileUploadListener="#{fileUploadController.handleFileUpload}"
                              mode="advanced" 
                              multiple="false" 
                              update="messages"
                              label="Select File"
                              sizeLimit="100000000" 
                              allowTypes="/(\.|\/)(gif|jpe?g|png|doc|docx|txt|pdf|html)$/"
                              auto="false"/>


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

上面添加了 widgetVar

在我的js中

<script type="text/javascript"> 
        function Naviagtion()
        {
            //alert("Sent to the printing holding queue, you may close this app now, your work will still print out ");
            window.setTimeout(afterDelay, 500);
            location.href = 'FilesUploaded.xhtml';

        }

        upload.buttonBar.find('input[type=file]').change(function() {
            if (this.value) {
                var files = upload.uploadContent.find('.files tr');

                if (files.length > 1) {
                    files.get(0).remove();
                }
            }
        });
    </script>

但我仍然能够多次上传,我的方向正确吗


虽然解决这个问题的更好行为应该是@BalusC 建议的,但在 primefaces 4.0 中我看到了该属性

fileLimit="1"

您可以将其设置为 1 以禁止使用“选择”按钮添加多个文件。当用户添加更多文件时,它只是说

“超出最大文件数”

本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)

Primefaces上传,如何在高级模式下只允许一次上传 的相关文章

随机推荐