【问题标题】:richface fileUpload onerror does not fire uprichface fileUpload onerror 不启动
【发布时间】:2014-08-04 14:11:53
【问题描述】:

我有一个 Richfaces 组件 - fileUpload 它的 onerror 方法即使服务器抛出异常也不会启动。这是组件的代码:

                        <rich:fileUpload

                            immediateUpload="true" 
                            acceptedTypes="pdf, txt, rtf, xls, xlsx, doc, docx, ppt, pptx, jpg, jpeg, mpg, mpeg"
                            allowFlash="true"
                            maxFilesQuantity="1"

                            fileUploadListener="#{bean.listener}"

                            onerror="alert('error');"
                            onuploadcomplete="alert('complete');"
                            >
                            <f:attribute name="typ" value="#{cc.attrs.typ}"></f:attribute>
                        </rich:fileUpload>

我的bean.listener 看起来像这样:

public void listener(final FileUploadEvent event) throws IOException, ConversionException {
    throw new RuntimeException("haha");

}

无论如何,我得到的唯一信息是complete 消息。 RichFaces 的版本是4.2.3。 有人遇到过这样的问题吗?

谢谢。

UPD。

好的,我查看了 Richfaces 4 文档,实际上没有 onerror 事件。似乎任何结果都是框架的成功。所以现在的问题是我如何对来自服务器的异常做出反应?

【问题讨论】:

    标签: java file-upload richfaces


    【解决方案1】:

    您可以收听uploadcomplete。它会发送您可以检查状态的项目,例如:

    onuploadcomplete="checkItems(event)"
    …
    
    checkItems = function(event) {
        var items = event.rf.data;
    
        for (var i = 0; i < items.length; i++) {
            if (items[i].state == "serverError") { // and/or "sizeExceeded"
                alert('error');
            }
        }
    }
    

    编辑: 啊,我看到您在侦听器中触发了异常。您将以这种方式捕获的异常将与将文件发送到服务器有关。在调用侦听器时,组件已交付文件,因此状态为“完成”。您必须自己处理侦听器中发生的异常。

    【讨论】:

    • 由于某种原因,“状态”变量是“完成”而不是“服务器错误”。
    猜你喜欢
    • 1970-01-01
    • 2013-01-06
    • 1970-01-01
    • 1970-01-01
    • 2012-06-05
    • 1970-01-01
    • 2017-10-24
    • 2020-08-04
    • 1970-01-01
    相关资源
    最近更新 更多