Primefaces - receiving files alphabetically in several file upload components

2 answers

Since the multi-file upload component is a jQuery-File-Upload plugin , the default state is not consistent, which means that all files are downloaded asynchronously.

, sequentialUploads true, . javascript.

, widgetVar fileUploadWV

<p:fileUpload widgetVar="fileUploadWV"
              fileUploadListener="#{attachmentBean.onUpload}" />

<script>
   $(function() {
      // setTimeout waits till the widgetVar is ready!
      setTimeout(sortFileUpload, 2000);
   });

   function sortFileUpload() {
      //Set this option to true to issue all file upload requests in a sequential order instead of simultaneous requests.  
      PF('fileUploadWV').jq.data().blueimpFileupload.options.sequentialUploads = true;

      //every time a new file is added, sort the files based on name
      PF('fileUploadWV').jq.change(function() {
          PF('fileUploadWV').files.sort(function fileSort(a, b) {
           return a.name.localeCompare(b.name)
          })
      });
   }
</script>

, .

: sequentialUploads true, , .

Github, -

enter image description here

, .

+9

, :

<p:remoteCommand action="#{attachmentBean.processAttachments}" 
    name="processAttachments" update="attachmentTable"/>  

<p:fileUpload fileUploadListener="#{attachmentBean.onUpload}" 
    oncomplete="processAttachments()" />

attachmentBean.onUpload /Map/SortedMap attachmentBean.processAttachments /Map

attachmentBean @ViewScoped

+1

Source: https://habr.com/ru/post/1533852/


All Articles