【问题标题】:PrimeFaces fileUpload adds files twicePrimeFaces fileUpload 两次添加文件
【发布时间】:2013-02-04 13:44:12
【问题描述】:

在我的项目中使用 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));
        }
    }
}

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

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

感谢您的任何建议和问候

帕斯卡

【问题讨论】:

    标签: jsf file-upload primefaces


    【解决方案1】:

    我偶然发现了这个解决方案。似乎包装滚动面板导致了这种行为。以下代码可以正常工作:

    <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 中的错误。

    【讨论】:

    • 一些文件一起上传时能得到文件列表吗?好像是运行状态,你解决了吗?
    猜你喜欢
    • 1970-01-01
    • 2012-05-28
    • 1970-01-01
    • 2012-05-28
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多