Don't like ads? PRO users don't see any ads ;-)
Guest

Untitled

By: a guest on Jun 9th, 2012  |  syntax: None  |  size: 0.82 KB  |  hits: 21  |  expires: Never
download  |  raw  |  embed  |  report abuse  |  print
Text below is selected. Please press Ctrl+C to copy to your clipboard. (⌘+C on Mac)
  1. JSF 2.0 redirect error
  2. @Named
  3. @RequestScoped
  4. public class LogoutBean implements Serializable
  5. {
  6.     public void preRenderView(ComponentSystemEvent e)
  7.     {
  8.         userSessionBean.logout();
  9.         FacesContext ctx = FacesContext.getCurrentInstance();
  10.         try
  11.         {
  12.             ctx.getApplication().getNavigationHandler().handleNavigation(ctx, null, "/pages/index?faces-redirect=true");
  13.         }
  14.         catch (IllegalStateException exc)
  15.         {
  16.             // Ignore. This exception is caused by redirecting after the response is already committed. The redirect works anyway.
  17.         }
  18.     }
  19.  
  20.     @Inject
  21.     private UserSessionBean userSessionBean;
  22. }
  23.        
  24. public void preRenderView(ComponentSystemEvent e) throws IOException {
  25.     FacesContext.getCurrentInstance().getExternalContext().redirect("pages/index.xhtml");
  26. }