根据两个 p:growl 中的严重性显示消息
我正在使用 PrimeFaces p:growl。
<p:growl id="msgsInfo"
rendered="true"
showDetail="true" />
<p:growl id="msgsError"
globalOnly="true"
showDetail="true"
sticky="true" />
我需要在第一个咆哮中仅显示 Info
消息,而在第二个咆哮中我需要显示 Error
消息。 当我添加错误消息时使用 globalOnly
会显示 2 次。
有什么想法吗?
I'm using PrimeFaces p:growl.
<p:growl id="msgsInfo"
rendered="true"
showDetail="true" />
<p:growl id="msgsError"
globalOnly="true"
showDetail="true"
sticky="true" />
I need to show in the first growl only Info
messages while in the second I need to show Error
messages.
Using globalOnly
when I add error message this is show 2 times.
Any idea?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
理论上,如果它支持
infoClass
、errorClass
等属性(如h:messages
),这是可能的。然后,您可以指定一个执行display: none
的 CSS 类。但
p:growl
不支持这些属性。在严重性级别上,您所能做的就是通过infoIcon
、errorIcon
等更改图标。所以您在这里很迷失。它可能值得功能请求。
请注意,
globalOnly="true"
仅显示具有null
客户端 ID 的消息,无论其严重性如何。It would in theory be possible if it supported
infoClass
,errorClass
, etc attributes like ash:messages
. You could then just specify a CSS class which does adisplay: none
.But the
p:growl
doesn't support those attributes. On the severity level all you can do is changing the icon byinfoIcon
,errorIcon
, etc. So you're pretty lost here.It might be worth a feature request.
Note that the
globalOnly="true"
only displays messages which have anull
client ID, regardless of their severity.请参阅我的答案
PrimeFaces咆哮动态改变颜色(多条消息)
您还可以找到生成以下内容的项目的源代码页面如下:
Please see my answer
PrimeFaces growl change color dynamically (Multiple messages)
You can also find the source code of the project which produces the page below:
我一直在寻找相同的功能(将咆哮从特定的消息严重性设置为粘性)。 PrimeFaces (6.1) 不提供此功能,但是很容易破解 咆哮 JavaScript。更具体地说,在
bindEvents
函数中,它们检查是否配置了sticky
并基于此:因此,您可以对
bindEvents
函数进行原型设计(覆盖)并根据消息严重性设置粘性
。您还可以构建
renderMessage
原型,并将严重性作为参数添加到bindEvents
。我选择使用快速技巧并从className
中读取它。我添加了这些实用函数:
现在您可以使用以下检查:
我可能会在 GitHub 上创建一个拉取请求,您可以在其中使用
上的
组件。stickSeverity
属性设置按摩棒的最低严重性p:growl这是完整的 JavaScript hack(PrimeFaces 6.1):
I was looking for the same functionality (to set the growl to sticky from a specific message severity). PrimeFaces (6.1) doesn't offer this functionality, but it is quite easy to hack the growl JavaScript. More specifically, in the
bindEvents
function they check ifsticky
was configured and based on that:So, you could prototype (override) the
bindEvents
function and setsticky
based on the message severity.You could also prototype
renderMessage
and add severity as a parameter tobindEvents
. I chose to used a quick hack and read it from theclassName
.I've added these utility functions:
Now you can use the following check:
I might create a pull request at GitHub where you can set the minimum severity to stick massages using the
stickSeverity
attribute on thep:growl
component.Here is the full JavaScript hack (PrimeFaces 6.1):