PrimeFaces fileUpload两次添加文件

时间:2013-02-04 13:44:13

标签: jsf file-upload primefaces

在我的项目中使用FileUpload时如下:

查看

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

视图模型

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

上传按预期工作。存储文件,所有已注册的组件都会更新,就像它应该的那样。但是,无论我是否使用拖放功能添加文件删除或“选择”按钮,文件总是两次添加到上传列表。

File upload is added twice.

这里发生了什么,我该如何解决这个问题?

感谢您的任何建议和最好的问候

帕斯卡

1 个答案:

答案 0 :(得分:1)

我偶然发现了解决方案。似乎包装scrollPanel导致此行为。以下代码可以正常运行:

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

必须是PrimeFaces 3.4中的错误。