During the render response phase, it's too late to create the flash scope. You need to do it at latest during invoke application phase. Basically, this problem has the same grounds as when doing so in a <f:event type="preRenderView">
as already answered in the following related questions:
- Adding faces message to redirected page using ExternalContext.redirect()
- Mojarra 2.1.14 flash scope messages and redirect to different path
In your particular case, you need a dummy view parameter so that the invoke action phase is triggered and then use the <f:event type="postInvokeAction">
(after having created the custom event yourself or having installed OmniFaces as per the answers on the abovelinked questions):
<f:metadata>
<f:viewParam name="dummy" />
<f:event type="postInvokeAction" listener="#{bean.init}" />
</f:metadata>
with
public void init() {
FacesContext context = FacesContext.getCurrentInstance();
context.addMessage(null, new FacesMessage("Faces Message: redirecting to page 2..."));
context.getExternalContext().getFlash().setKeepMessages(true);
ConfigurableNavigationHandler nav = (ConfigurableNavigationHandler) context.getApplication().getNavigationHandler();
nav.performNavigation("redirect-to-page2");
}
or if you've chosen for OmniFaces
public void init() {
Messages.addFlashGlobalInfo("Faces Message: redirecting to page 2...");
Faces.navigate("redirect-to-page2");
}