PrimeFaces 3.3 brings handy features regarding displaying facesmessages. These features were already available in PrimeFaces Extensions Project with a different implementation and there was a popular community request to promote these ideas to PrimeFaces. Also during a team meeting last week, our consultants mentioned that they needed at least two of these during their work onsite for a client where they provide onsite assistance on PrimeFaces. Long story short, here are the 3 additions;
Targetable Messages
There maybe times where you need to target a FacesMessage to a specific component, for example suppose you have p:growl and p:messages on same page and you need to display some messages on growl, some on p:messages. We have added grouping defined via for attribute to implement these;
<p:messages for="somekey" /> <p:growl for="anotherkey" /> <p:growl globalOnly="true" />
context.addMessage("somekey", new FacesMessage(FacesMessage.SEVERITY_INFO,"Sample info message", "PrimeFaces Rocks"));
context.addMessage("somekey", new FacesMessage(FacesMessage.SEVERITY_INFO,"Sample info message", "Always bet on Prime"));
context.addMessage("anotherkey", new FacesMessage(FacesMessage.SEVERITY_INFO,"Sample info message", "PrimeFaces is developed by Chuck Norris"));
context.addMessage(null, new FacesMessage(FacesMessage.SEVERITY_INFO,"Sample warn message", "Optimus Prime will be back!"));
So first two messages will be displayed by messages, second one by first growl and last with second growl.
Severity Levels
Using severity attribute of messages components, you can defined which severities can be displayed by the component. So for instance, we are now able to display errors on messages and infos on a growl that fades out.
<p:messages severity="error" /> <p:growl severity="info, warn" /> <p:growl /> //default
Escaping
Until now message components, escape the html content in FacesMessage summary and detail, just set escape to false to display html inside messages.
context.addMessage(null, new FacesMessage(FacesMessage.SEVERITY_INFO,"Sample warn message", "PrimeFaces is developed by <strong>Chuck Norris!</strong>"));
<p:messages escape="false" />
That’s it! Hope you find these features handy, we’ve already started using targeting and severity levels in a project!
Cool, thanks!
Thanks to Extensions Project Team for pushing us to promote this to core
will the escape also be present in p:growl?
These apply to message, messages and growl.
Long waiting features are finally here. Happy to see these in the core. Time to push and promote more stuff to the core
.
Thank you. Nice teamwork guys and keep up the good work
Always bet on prime!!
And how can we get access to this funcionality right now?
3.3-SNAPSHOT from repo or you can build PF from source.
Hi! This enhancement will work if i have a p:message in a p:dialog and another global p:message for the main page?
thnx a lot for you work!
Yes sure, if you use targeting.
I’ve been waiting for this! Great addition!
Thanks for the continious useful updates
This was a very helpful feature…Thanks Prime Faces Team !!