【问题标题】:PrimeFaces fileupload not uploading the second and upcoming filesPrimeFaces fileupload 不上传第二个和即将到来的文件
【发布时间】:2018-05-08 06:29:39
【问题描述】:

我正在使用 primefaces 3.4.2。

我正在尝试上传多个文件,但每次选择一次,但第一个文件调用了侦听器,而行中的其他文件没有调用侦听器。

可能导致此问题的原因是什么?
这是jsf页面的相关部分

<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>

这是听者

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();
}

【问题讨论】:

  • multiple="true" 不起作用
  • 附加文件没有上传还是只是没有调用监听器?并尝试更新的 PF 版本。你的年龄 > 5 岁
  • @Kukeltje 未调用侦听器。我很想更新 PF 版本,但不幸的是,这个决定不是我能做出的。
  • 我说试试(不用于生产)。知道新版本中是否修复了某些东西总是好的,总是好的......然后你可以例如检查来源,查找差异等,如果您无法升级,可以自己创建补丁。我个人没有时间在新版本中寻找可能已经修复(通过“意外”或故意)的旧版本中的问题......(而且我几乎 100% 肯定有关于这方面的事情问题列表...也检查一下(您应该在发布之前这样做...)干杯

标签: primefaces jsf-2


【解决方案1】:

最好的情况是更新 primefaces 版本,因为您可以在 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}"/>

但如果你不能,你可以尝试这样的事情:

Sequential Uploads by JavaScript

【讨论】:

    猜你喜欢
    • 2023-03-19
    • 2013-12-16
    • 2013-06-06
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2013-05-03
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多