1

I am using primefaces 3.4.2.

I am trying to upload multiple files but selected once per selection, but the listener is called for the first file and listener is not called for the other files in the row.

What might be causing this problem?
This is the related part of jsf page

<p:dialog id="uploadNcstFileDialog" closable="true"
        widgetVar="uploadFileWidget" header="file Upload" modal="true"
        resizable="false">
        <h:form id="uploadFileForm" prependId="false"
            enctype="multipart/form-data">
            <h:outputLabel value="Choose a file to upload" />
            <p:panel style="width:600px;height:200px;">
                <p:fileUpload
                    fileUploadListener="#{bulkSmsMainBean.handleFileUpload}"
                    mode="advanced" uploadLabel="Upload" cancelLabel="Stop"
                    label="Dosya Seç" allowTypes="/(\.|\/)(pdf|gif|jpe?g|doc(x)?|xls(x)?|msg)$/"
                    invalidFileMessage="#{msgs['docformat.error']}"
                    update=":bulkSmsDetailTabs:bulkSmsDocumentListForm:documentListDataTableId" />
                <p:commandButton styleClass="button-type4"
                    style="float:right;margin-top:22px" value="Cancel" position="right"
                    onclick="uploadFileWidget.hide();return false;" />
            </p:panel>
        </h:form>
    </p:dialog>

This is the listener

public void handleFileUpload(FileUploadEvent event) {
    UploadedFile uploadedFile = event.getFile();
    String fileName = uploadedFile.getFileName();
    int pos = fileName.lastIndexOf('.');
    String ext = fileName.substring(pos + 1);

    if (uploadedFile.getFileName().contains("\\")) {
        fileName = fileName.substring(fileName.lastIndexOf('\\', fileName.length()) + 1);
    }


    loadDocumentList();
}

enter image description here

Kukeltje
  • 12,223
  • 4
  • 24
  • 47
Salih Erikci
  • 5,076
  • 12
  • 39
  • 69
  • Try to set multiple="true" as in the Showcase https://www.primefaces.org/showcase/ui/file/upload/multiple.xhtml and check the documentation https://www.primefaces.org/docs/guide/primefaces_user_guide_3_4.pdf – Mihawk May 08 '18 at 07:13
  • multiple="true" didn't work – Salih Erikci May 08 '18 at 07:38
  • Are the additional files not uploaded or is the listener just not called? And TRY newer PF versions. Yours is >5 years old – Kukeltje May 08 '18 at 10:07
  • @Kukeltje the listener is not called. I would love update PF version but unfortunately that decision is not mine to make. – Salih Erikci May 08 '18 at 10:45
  • I said TRY (not use in production). It is always, always, always good to just know if something is fixed in newer releases... Then you can e.g. check the sources, find the differences etc and maybe create a patch yourself if you cannot upgrade. I personally don't have the time chasing issues in old versions that might have already been fixed (either by 'accident' or on purpose) in newer versions... (and I'm almost 100% sure there are things about this in the issuelist... Check those too (you should have done that before posting... ) Cheers – Kukeltje May 08 '18 at 10:49
  • Any logs either in client/server side? Do debugging through `FacesServlet`. – Aritz May 14 '18 at 11:06

1 Answers1

1

The best scenario is update the primefaces version, because you could use sequential attribute in version 5.3 >.

Sequential attribute to fileUpload - Primefaces Project

<p:fileUpload mode="advanced" dragDropSupport="true" multiple="true"
                          sequential="true"
                          label="Procurar XML" cancelLabel="Cancelar" uploadLabel="Importar"
                          allowTypes="/(\.|\/)(xml)$/" sizeLimit="100000"
                          fileUploadListener="#{doctosFiscaisImportarController.uploadFile}"/>

But if you can't you could try something like this:

Sequential Uploads by JavaScript

Guilherme Bernardi
  • 490
  • 1
  • 6
  • 18