简体   繁体   English

rich:fileUpload in JSF version 3.3.3 final, 1 个文件上传导致文件上传侦听器在 Firefox v69 中运行两次

[英]rich:fileUpload in JSF version 3.3.3 final, 1 file uploaded causes file upload listener to run twice in Firefox v69

For some reason, best guess is something todo with how broswer handles the ajax event a single fileupload triggers the event listener in Java twice.出于某种原因,最好的猜测是浏览器如何处理 ajax 事件,单个文件上传两次触发 Java 中的事件侦听器。

The problem is worst in Firefox.这个问题在 Firefox 中最为严重。

Latest Chrome version and in old Firefox v28(2014) general work.最新的 Chrome 版本和旧的 Firefox v28(2014) 一般工作。

Objective is to upload and process a single file: - restrict it to a single file upload - check to see if the uploaded file is valid XML - save the uploaded file in another location which a newly generated name - delete the temp file目标是上传和处理单个文件: - 将其限制为单个文件上传 - 检查上传的文件是否为有效的 XML - 将上传的文件保存在新生成的名称的另一个位置 - 删除临时文件

Richfaces FileUpload side: Richfaces 文件上传端:

<a4j:form id="formFileUpload">
    <h:panelGrid id="fileUploadSection" columns="1" width="100%">

        <!-- ##### File uploader ##### -->
        <!-- https://docs.jboss.org/richfaces/latest_3_3_X/en/devguide/html/rich_fileUpload.html -->
        <rich:spacer width="10px" height="0px" />
        <h:outputText value="Upload file candidate:" />
        <rich:fileUpload fileUploadListener="#{attributeConfigurationMgr.validateFileUploadListener}"
                         addControlLabel="Select File..."
                         id="upload"
                         immediateUpload="true"
                         allowFlash="false"
                         noDuplicate="true"
                         listHeight="55px"
                         onupload="console.log('fileupload onupload:'+Date.now())"
                         oncomplete="console.log('fileupload complete:'+Date.now())"
        >
            <a4j:support event="onuploadcomplete" ajaxSingle="true" reRender="validatePanel, validationFilesTable, fileUploadSection"  />
        </rich:fileUpload>
    </h:panelGrid>
    </a4j:form>

Java side event listener: Java 侧事件侦听器:

As 2 events get generated I have tried to identified check that the same temp uploaded file isn't being processed to avoid double processing, it seems through maybe the temp upload file isn't always fully there.当生成 2 个事件时,我试图确定是否未处理相同的临时上传文件以避免双重处理,似乎临时上传文件并不总是完全存在。

Is their a way to detect the file upload header size?他们是一种检测文件上传标头大小的方法吗? Then I could check to see if the temp file is the correct size or not?然后我可以检查临时文件的大小是否正确?

private String lastUploadedFile = null;

public synchronized void validateFileUploadListener(final UploadEvent event) {

UploadItem item = event.getUploadItem();
File uploadedFile = item.getFile();
String uploadedFileName = item.getFileName();

    if (lastUploadedFile != null && lastUploadedFile.contentEquals(uploadedFileName))
    {
        // check doesn't it have the same file upload name
        firstEvent = false;
    }
    else
    {
        // set name as hopefully first upload event
        lastUploadedFile = uploadedFileName;
        firstEvent = true;
    }

if(Files.exists(uploadedFile.toPath())) {
// find XSD file to validate against
// validate against xsd
// save file
// temp file delete
}

}

I don't know the inner workings of RF 3 all that well, but:我不太了解 RF 3 的内部工作原理,但是:

If this is browser related I'm assuming the form is being submitted twice.如果这是浏览器相关我假设表单被提交两次。 If that's the case you should be able to intercept that.如果是这种情况,您应该能够拦截它。 FileUpload.upload is a public method, the general form-submitting method appears to be _JSFFormSubmit . FileUpload.upload是一个公共方法,一般的表单提交方法似乎是_JSFFormSubmit You can override one of those methods and providing you tell apart the duplicate cancel the execution.您可以覆盖这些方法之一,并提供您区分重复项取消执行。

If you cannot detect things on the client side you can intercept server requests by implementing a javax.servlet.Filter (the same way RichFaces does, using org.ajax4jsf.webapp.BaseFilter ).如果您无法在客户端检测到事物,您可以通过实现javax.servlet.Filter (与 RichFaces 相同,使用org.ajax4jsf.webapp.BaseFilter )来拦截服务器请求。 That way you'll have access to request headers.这样您就可以访问请求标头。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM