Keep the message in the flash scope. It’ll survive the redirect.
context.addMessage(clientId, message);
externalContext.getFlash().setKeepMessages(true);
return "users.xhtml?faces-redirect=true";
Note that older Mojarra versions have some peculiar Flash scope related bugs:
- issue 1755 – Flash scoped messages lives longer than next request – fixed in 2.0.7 / 2.1.4
- issue 2130 – Flash cookie enables data exploits – fixed in 2.1.24 / 2.2.1
- issue 2140 – Flash cookie not available when redirected to different path – fixed in 2.1.14 / 2.2.0
- issue 2906 – Flash cookie uses wrong path for applications on root – fixed in 2.1.24 / 2.2.1
- issue 2959 – Flash creates sometimes version1 cookie which fail in IE – fixed in 2.1.25 / 2.2.2
- issue 2977 – Flash causes NPE on stale cookies after a session expire – fixed in 2.1.25 / 2.2.2
- issue 2866 – Flash cookie not cleared when stale – fixed in 2.1.27 / 2.2.5
You’d best to upgrade to a minimum of Mojarra 2.1.27 / 2.2.5 in order to ensure that your application is not affected by this.