FacesMessage Enhancements

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!

This entry was posted in PrimeFaces. Bookmark the permalink.

13 thoughts on “FacesMessage Enhancements

  1. Long waiting features are finally here. Happy to see these in the core. Time to push and promote more stuff to the core :-) .

  2. 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!