tags:

views:

62

answers:

1

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: https://javaserverfaces.dev.java.net/issues/show_bug.cgi?id=1635

A: 

You're right.

The JSF 2 flash scope is currently extremly buggy, and based on the specification, will probably remain almost unusable: https://javaserverfaces.dev.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

Lincoln