我正在使用<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/