1
votes

When using FileUpload in my project as follows:

View

<h2>#{bundle['upload']}</h2>
<p:scrollPanel id="upload" styleClass="ui-widget-filebucket-upload">
    <h:form enctype="multipart/form-data">
        <p:fileUpload fileUploadListener="#{fileBucket.handleFileUpload}"
            mode="advanced" update=":download:files :messages"
            multiple="false" label="#{bundle['choose_button']}"
            uploadLabel="#{bundle['upload_button']}"
            cancelLabel="#{bundle['cancel_button']}" />
    </h:form>
</p:scrollPanel>
<p:resizable for="upload" />

ViewModel

@ViewScoped
@Named("fileBucket")
public class DefaultFileBucketViewModel implements IFileBucketViewModel, Observer, Serializable {
    // ...
    public void handleFileUpload(FileUploadEvent event) {
        try {
            model.write(id, event.getFile().getFileName(), event.getFile().getInputstream());
        } catch (final Exception e) {
            log.error(e);
            messages.error(new BundleKey(Literals.BUNDLE_NAME, Literals.FILE_UPLOAD_ERROR));
        }
    }
}

The upload works as intended. The file is stored, all registered components are updated, just as it's supposed to be. However, no matter whether I'm adding the file using drag & drop or the "Choose" button, the file is always added twice to the upload list.

File upload is added twice.

What's happening here and how can I fix this?

Thanks for any suggestions and best regards

Pascal

1

1 Answers

1
votes

I stumbled by chance over the solution. It seems the wrapping scrollPanel is causing this behavior. The following code works without issues:

<h2>#{bundle['upload']}</h2>
<h:form enctype="multipart/form-data" id="upload"
    styleClass="ui-widget-filebucket-upload ui-widget-content ui-corner-bottom ui-corner-top">
    <p:fileUpload id="upload_control"
        fileUploadListener="#{fileBucket.handleFileUpload}" mode="advanced"
        update=":download:files :messages" multiple="false"
        label="#{bundle['choose_button']}"
        uploadLabel="#{bundle['upload_button']}"
        cancelLabel="#{bundle['cancel_button']}" />
</h:form>
<p:resizable for="upload" />

Must be a bug in PrimeFaces 3.4.