How to use Primefaces' p:growl and redirect to a page

arkantos picture arkantos · Mar 29, 2012 · Viewed 20.8k times · Source

hi im kind of new at jsf enviroment, im trying to update a primefaces growl and then redirect to a page from a commandButton action.

 <p:commandButton value="Guardar"  action="#{AgendamientoMBean.procesaAgendamientoJ()}" 
 update="growlDetalle" />  

The managed bean code its

   FacesContext context = FacesContext.getCurrentInstance();
   context.addMessage(null, new FacesMessage(FacesMessage.SEVERITY_INFO, descripcion, detalle));
   ....
   ....
    return "agp_bandeja_citas_llamadas?faces-redirect=true";

This only redirectme to the page but doesnt show me the growl message, i tested that if change my method to not return the page the message does show..

I was trying to update the growl of the page that im redirecting but thats impossible i guess.

i think that when redirecting i lost the update functionality because im in new page now.

Is there a way to tell jsf to first do the update and then redirecting?

Hope you can help me, thanks in advance

Answer

Matt Handy picture Matt Handy · Mar 29, 2012

Messages get lost during redirect. You can use the flash to keep messages.

Add the following before returning from your action method:

FacesContext context = FacesContext.getCurrentInstance();
context.getExternalContext().getFlash().setKeepMessages(true);