<p:growl> and <p:messages> in a same page
In the growl's demo page of PrimeFaces, they mentioned that: "Growl simply replaces h:messages component.". I'm afraid that you may not be able to achieve your goal because growl will also display all FacesMessage in the View.
However, if you reverse your requirement - display errors using <p:growl>
& display successful messages using <p:message>
, you can actually achieve that as following:
<p:message id="successMsg" for="successMsg" />
@ManagedBean
@RequestScoped
public class MrBean {
public void doSomething() {
FacesContext context = FacesContext.getCurrentInstance();
if (failed) {
context.addMessage(null, new FacesMessage("Failed", "Sry boss! I have failed."));
} else {
context.addMessage("successMsg", new FacesMessage("Successful", "Hey boss! I did it!"));
}
}
}
JSF:
<p:messages for="somekey" />
<p:growl for="anotherkey" />
Bean:
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"));a
context.addMessage("anotherkey", new FacesMessage(FacesMessage.SEVERITY_INFO,"Sample info message", "PrimeFaces is developed by Chuck Norris"));
This just worked fine with me!
It looks like as of PrimeFaces 3.3 you can do what you wanted to do:
http://blog.primefaces.org/?p=1894
You can now do:
<p:messages severity="error" />
<p:growl severity="info, warn" />
with
context.addMessage("somekey", new FacesMessage(FacesMessage.SEVERITY_ERROR,"Error Title", "Error Message"));
context.addMessage("somekey", new FacesMessage(FacesMessage.SEVERITY_INFO,"Success Title", "Success Message"));