When multiple upload is finished in p:fileUpload?

后端 未结 2 677
无人及你
无人及你 2020-12-09 13:36

I have a multiple p:fileUpload, I need to upload from 1 to N files on server, after uploading I need to know how many files were uploaded and then start process

相关标签:
2条回答
  • 2020-12-09 14:21

    For other people who may face the same problem.

    The file upload component has 'files' property which contain the list of files to be uploaded. As soon as a file uploaded it is removed from the 'files' array, thus when last file is uploaded the 'files' will be empty. This could be used to detect the moment when the last file is uploaded. Afterwards you can trigger remote command to do whatever you want.

    Code example:

    <h:form enctype="multipart/form-data">
        <p:fileUpload id="files"
                 widgetVar="fileUploadWidget"
                 mode="advanced"
                 multiple="true"
                 oncomplete="handleMultiFileUploadRequest(PF('fileUploadWidget'), validateFiles);"/>
    
        <p:remoteCommand name="validateFiles" actionListener="#{Your action}"/>
    
        <script type="text/javascript">
            function handleMultiFileUploadRequest(fileupload, remoteButton) {
                if (fileupload.files.length === 0) {
                    if (remoteButton) {
                        remoteButton();
                    }
                }
            }
        </script>
    </h:form>
    
    0 讨论(0)
  • 2020-12-09 14:32

    You can validate a modal dialog, until you finish the process, and ends when you close it.

    0 讨论(0)
提交回复
热议问题