Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to specify whether the message should show up in p:growl or p:messages?

In my Facelets page I have this:

<p:growl id="msg1" life="1500"/>

and another

<p:messages id="msg2"/>

I need the following message to show up in <p:messages> only.

FacesContext.getCurrentInstance().addMessage(null, new FacesMessage("veillez saisir les champs obligatoires (*)", null));

But it also shows up in <p:growl>.

How do I specify where the message should show up?

like image 600
Hayi Avatar asked May 16 '12 20:05

Hayi


1 Answers

Extracted from primefaces manual. Page 282.

Targetable Messages

There may be times where you need to target one or more messages to a specific message component, for example suppose you have growl and messages on same page and you need to display some messages on growl and some on messages. Use for attribute to associate messages with specific components.

<p:messages for="somekey" />
<p:growl for="anotherkey" />

The Bean

FacesContext context = FacesContext.getCurrentInstance();
context.addMessage("somekey", facesMessage1);
context.addMessage("somekey", facesMessage2);
context.addMessage("anotherkey", facesMessage3);

In sample above, messages will display first and second message and growl will only display the 3rd message.

like image 83
Jonathas Pacífico Avatar answered Sep 21 '22 16:09

Jonathas Pacífico