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?
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With