Question

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

Was it helpful?

Solution

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

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top