【问题标题】:How to display message about maximum file size restriction in RichFaces 4 fileUpload component如何在 RichFaces 4 fileUpload 组件中显示有关最大文件大小限制的消息
【发布时间】:2013-11-29 19:42:13
【问题描述】:

我已经使用 RichFaces 4.3 实现了文件上传。文件上传工作正常,关于文件类型的警报工作正常,但关于最大文件大小限制的警告没有。文件上传代码:

<rich:fileUpload id="bannerUpload"
    fileUploadListener="#{bean.bannerListener}"
    acceptedTypes="png, gif, jpg, jpeg"
    ontyperejected="alert('#{msg.bannerFormatRestriction}');"
    maxFilesQuantity="1"
    sizeExceededLabel="File size is restricted. Max allowed size is 1 MB."
    serverErrorLabel="File was not uploaded. Please try again."
    addLabel="Select image for banner">
</rich:fileUpload>

设置上下文参数并且限制起作用。但不显示警报消息。任何建议表示赞赏。

更新

消息问题与fileupload.js.jsf line 213有关。
Firebug 中的错误消息:Load denied by X-Frame-Options: ...?rf_fu_uid=... does not permit framing.Error: Permission denied to access property 'document' var contentDocument = event.target.contentWindow.document

【问题讨论】:

    标签: jsf-2 richfaces


    【解决方案1】:

    您需要一种机制来显示fileUpload 生成的面孔消息,例如:

    <rich:message for="bannerUpload" showDetail="true" ajaxRendered="true"/> 
    

    更新

    根据错误文本"Load denied by X-Frame-Options: ...?rf_fu_uid=... does not permit framing.",在我看来有两个可能的原因:

    1. X-Frame-Options 标头的值为 DENY。将其更改为 SAMEORIGIN 以允许为您的网站设置框架。
    2. X-Frame-Options 标头的值为 SAMEORIGIN,但由于某种原因,fileUpload 会尝试将来自不同域的内容放入框架中。

    两者都可以在 Firebug 的 Network 选项卡上检查。

    【讨论】:

    • 谢谢安德烈。关于限制的消息显示在 fileUpload 组件内,与rich:message 或rich:messages 无关。在发布问题之前,我已经对其进行了测试(使用 rich:message 和 rich:messages)。在我的情况下,消息问题与 fileupload.js.jsf 第 213 行有关。Firebug 显示:“X-Frame-Options 拒绝加载:...?rf_fu_uid=... 不允许分帧。”和“错误:访问属性'文档'的权限被拒绝”“var contentDocument = event.target.contentWindow.document”。
    • @VasilLukach 我已根据您提供的萤火虫日志更新了我的答案。
    • 删除 X-FRAME-OPTIONS 后,所有消息都会正确显示。谢谢安德烈。
    • 不客气,Vasil,如果出于安全原因设置了标头,则将其值设置为 SAMEORIGIN 对于rich:fileUpload 应该足够了。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2014-05-01
    • 2015-09-16
    • 1970-01-01
    • 1970-01-01
    • 2023-03-30
    • 1970-01-01
    • 2015-08-29
    相关资源
    最近更新 更多