You can obtain access to the Flash
object from the ExternalContext
:
Obtain access to the
Flash
:Flash flash = FacesContext.getCurrentInstance().getExternalContext().getFlash();
Set
keepMessages =true
on the object, to ensure that theFacesMessage
you store in it survives the redirectflash.setKeepMessages(true);
Store your
FacesMessages
using theputNow
method, to ensure that even after the redirect, the messages will survive at least one page refreshflash.putNow(yourFacesMessage);
You really don't need to store the FacesMessage
in the flash object itself; queuing them in the FacesContext
is enough to guarantee that they'll be available on the other page
Related: