tôi đang tìm kiếm các chức năng tương tự (để đặt tiếng gầm thành dính từ mức độ nghiêm trọng của thông báo cụ thể). PrimeFaces (6.1) không cung cấp chức năng này, nhưng khá dễ hack growl JavaScript. Cụ thể hơn, trong bindEvents
chức năng họ kiểm tra xem sticky
đã được cấu hình và trên cơ sở đó:
//hide the message after given time if not sticky
if(!sticky) {
this.setRemovalTimeout(message);
}
Vì vậy, bạn có thể chế tạo thử nghiệm (ghi đè) các bindEvents
chức năng và thiết lập sticky
dựa trên mức độ nghiêm trọng thông báo.
PrimeFaces.widget.Growl.prototype.bindEvents = function(message) {
var _self = this,
sticky = this.cfg.sticky;
// Start hack
if (!sticky) {
// Your rule
}
...
Bạn cũng có thể tạo mẫu renderMessage
và thêm mức độ nghiêm trọng làm tham số bindEvents
. Tôi đã chọn sử dụng một bản hack nhanh và đọc nó từ className
.
Tôi đã thêm những chức năng tiện ích:
var SEVERITIES = [ "info", "warn", "error", "fatal" ];
function getSeverity(domNode) {
// HACK Severity can be found in the className after the last - character.
var severity = domNode.className;
return severity.substring(severity.lastIndexOf("-") + 1);
}
function getSeverityIndex(severityString) {
return SEVERITIES.indexOf(severityString);
}
Bây giờ bạn có thể sử dụng việc kiểm tra sau:
if (!sticky) {
sticky = getSeverityIndex(getSeverity(message[0])) >= getSeverityIndex("error");
}
tôi có thể tạo một yêu cầu kéo tại GitHub nơi bạn có thể thiết lập mức độ nghiêm trọng tối thiểu để massage thanh bằng cách sử dụng thuộc tính stickSeverity
trên thành phần p:growl
.
Đây là bản hack JavaScript đầy đủ (PrimeFaces 6.1):
var SEVERITIES = [ "info", "warn", "error", "fatal" ];
function getSeverity(domNode) {
// HACK Severity can be found in the className after the last - character.
var severity = domNode.className;
return severity.substring(severity.lastIndexOf("-") + 1);
}
function getSeverityIndex(severityString) {
return SEVERITIES.indexOf(severityString);
}
PrimeFaces.widget.Growl.prototype.bindEvents = function(message) {
var _self = this,
sticky = this.cfg.sticky;
// Start customization
if (!sticky) {
sticky = getSeverityIndex(getSeverity(message[0])) >= getSeverityIndex("error");
}
// End customization
message.mouseover(function() {
var msg = $(this);
//visuals
if(!msg.is(':animated')) {
msg.find('div.ui-growl-icon-close:first').show();
}
})
.mouseout(function() {
//visuals
$(this).find('div.ui-growl-icon-close:first').hide();
});
//remove message on click of close icon
message.find('div.ui-growl-icon-close').click(function() {
_self.removeMessage(message);
//clear timeout if removed manually
if(!sticky) {
clearTimeout(message.data('timeout'));
}
});
//hide the message after given time if not sticky
if(!sticky) {
this.setRemovalTimeout(message);
}
}
Hiện tại bạn có thể thực hiện. Trong thực tế, có vẻ như nó đã có sẵn trong một thời gian http://stackoverflow.com/questions/20465674/is-possible-use-tow-growls-in-one-page – SJuan76