jsf - 如何显示p :fileUpload invalidFileMessage in p:growl

标签 jsf file-upload primefaces message growl

我正在使用<p:fileUpload>仅限于 PDF。然而,invalidFileMessage显示在 <p:fileUpload> 内成分。我怎样才能在<p:growl>中显示它相反?

<p:fileUpload allowTypes="/(\.|\/)(pdf)$/"
              invalidFileMessage="File is Invalid. Only PDF files are allowed" />

最佳答案

您无法处理此服务器端。文件类型在客户端进行验证,而无需在服务器端执行任何代码。因此,任何建议手动创建 FacesMessage 的建议和/或明确添加 <p:message(s)>未经深思熟虑且未经测试。

You should use jQuery. It solves everything.

基于 fileupload.js 源代码,你最好的选择是听虚构的 show消息容器的事件,然后将消息容器移动到表单的末尾。

第一次扩展$.show()实际触发show事件。

(function($) {
    var originalShowFunction = $.fn.show;
    $.fn.show = function() {
        this.trigger("show");
        return originalShowFunction.apply(this, arguments);
    };
})(jQuery);

然后只需在 show 上创建一个监听器即可事件基本上在文件上传消息出现时运行,然后解析每条消息并使用 renderMessage() <p:growl>的功能JS API。下面的示例假设您有 <p:growl widgetVar="growl">在同一页面的某个地方。

$(document).on("show", ".ui-fileupload-content>.ui-messages", function() {
    $(this).children().hide().find("li").each(function(index, message) {
        var $message = $(message);
        PF("growl").renderMessage({
            summary: $(".ui-messages-error-summary", $message).text(),
            detail: $(".ui-messages-error-detail", $message).text()
        });
    });
}); 

关于jsf - 如何显示p :fileUpload invalidFileMessage in p:growl,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16684750/

相关文章:

asp.net - 从表单发布的文件中获取 FileStream

jsf-2 - 如何使用 <p :blockUI> on whole view?

jsf - PrimeFaces LazyDataModel 高级过滤器

java.lang.NumberFormatException : For input string: "currPage"

jsf - 尝试显示动态生成的条形码时显示上一个条形码

jsf - PrimeFaces Dialog + appendToBody=true 不起作用

PHP 自动递增文件名

javascript - Extjs 无法在文件已上传后再次上传文件

java - Facelets 中的 Spring Security 注销链接

primefaces - 如何通过 id 在 Primefaces tabview 中设置事件选项卡?