Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to show faces message in the redirected page

I have provided an interface that allows users to create accounts for an application. At the end of the process the registration method performs the registration process adds a success message to the page and then navigates the user to a central data table that displays all the system users.

The problem I have is that the success message never gets displayed because of the page redirect. I can't have a wait() in the method because the JSF message won't get displayed until the method has completed. Ideally I want the success message to be displayed and then a specified time later the page is redirected.

How can I achieve this?

like image 704
tarka Avatar asked Dec 03 '12 14:12

tarka


1 Answers

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.

like image 129
BalusC Avatar answered Oct 31 '22 08:10

BalusC