3

I am using JSF2.0 Mojarra 2.0.2.

I have a method that logs out a user and puts a logout message in the flash, forwards to the login page (which has a div that prints out the flash). However, when I use navigationHandlers handleNavigation method for some reason the flash is not being displayed. I have a similar method that forwards a user to the login page if he/she isn't logged in.

If I handle the navigation through an h:link and just call the logout method directly, the flash is displayed as normal, but if I use the handleNavigation() method, the flash is cleared for some reason.

The code in question is:

public void performLogout()
{
    getFacesContext().getExternalContext().invalidateSession();
    setCurrentUser(null);
    getFlash().put("notice", "Successfully logged out.");
    super.getFacesContext().getApplication().getNavigationHandler()
            .handleNavigation(getFacesContext(), null, "login");
}

Is there some way I can keep the flash when navigating like this?

thanks.

Edit: I believe this issue is related to another issue involving the flash not being preserved during redirects when xhtml pages are in different directories: http://java.net/jira/browse/JAVASERVERFACES-1635

BalusC
  • 1,082,665
  • 372
  • 3,610
  • 3,555
kgrad
  • 4,672
  • 7
  • 36
  • 57

1 Answers1

2

You're right.

The JSF 2 flash scope is currently extremly buggy, and based on the specification, will probably remain almost unusable: http://javaserverfaces.java.net/nonav/docs/2.0/javadocs/index.html

If you'd like a flash scope that works as follows, consider using CDI, and the flash scope from Seam Faces - http://docs.jboss.org/seam/3/faces/reference/snapshot/en-US/html_single/#flashscoped

"The flash scope should be active from the moment an object is placed in the scope, until the moment the response has completed rendering."

--Lincoln

BalusC
  • 1,082,665
  • 372
  • 3,610
  • 3,555
Lincoln
  • 3,151
  • 17
  • 22
  • I just came across this issue myself. Would you mind elaborating on the solution? I am already using CDI, but not Seam Faces. Do I need to create a CDI bean with an `@Inject Flash flash` field? What scope? How would I access it from the bean that handles logging out? – Matt Ball Dec 08 '10 at 20:48
  • 2
    It's almost a year later now and it still seems very buggy. Is The Flash ever going to be improved? Why are not more books and articles warning against The Flash? – Mike Braun Jun 20 '11 at 20:34
  • It indeed seems buggy. Also see http://stackoverflow.com/questions/3343147/removing-jsf-messages-from-the-flash/6404047#6404047 – Arjan Tijms Jun 20 '11 at 21:38