eclipse-ee4j / mojarra

Mojarra, a Jakarta Faces implementation
Other
163 stars 111 forks source link

NullPointerException in NavigationHandlerImpl #2023

Closed ren-zhijun-oracle closed 11 years ago

ren-zhijun-oracle commented 13 years ago

I have used GF3.0.1 for many months and created a "public class LoginFilter implements PhaseListener" to control timeout session, to redirect the user to login page. All worked fine in this version. Now, I migrated to GF3.1 and the code for LoginFilter doesn't work anymore. The wepapp arises this exception: java.lang.NullPointerException at com.sun.faces.application.NavigationHandlerImpl.updateRenderTargets(NavigationHandlerImpl.java:240) at com.sun.faces.application.NavigationHandlerImpl.handleNavigation(NavigationHandlerImpl.java:197) at util.LoginFilter.afterPhase(LoginFilter.java:42) at com.sun.faces.lifecycle.Phase.handleAfterPhase(Phase.java:189) at com.sun.faces.lifecycle.Phase.doPhase(Phase.java:107) at com.sun.faces.lifecycle.RestoreViewPhase.doPhase(RestoreViewPhase.java:113) at com.sun.faces.lifecycle.LifecycleImpl.execute(LifecycleImpl.java:118) ...

The faces-config.xml has this config:

util.LoginFilter * logout /logins.xhtml

The complete class is here: package util;

import entity.Usuario; import javax.faces.application.NavigationHandler; import javax.faces.component.UIViewRoot; import javax.faces.context.ExternalContext; import javax.faces.context.FacesContext; import javax.faces.event.PhaseEvent; import javax.faces.event.PhaseId; import javax.faces.event.PhaseListener; import javax.servlet.ServletContext; import javax.servlet.http.HttpSession;

public class LoginFilter implements PhaseListener {

private static final long serialVersionUID = 1L;

@Override public void beforePhase(PhaseEvent event) { FacesContext fc = event.getFacesContext(); ExternalContext ec = fc.getExternalContext(); HttpSession session = (HttpSession) ec.getSession(false); if (session == null) { try

{ String url = ((ServletContext)ec.getContext()).getContextPath(); ec.redirect(url + "/index.jsp"); }

catch (Exception e)

{ e.printStackTrace(); }

} }

@Override public void afterPhase(PhaseEvent event) { FacesContext fc = event.getFacesContext(); try { UIViewRoot view = fc.getViewRoot(); if (view == null)

{ NavigationHandler nh = fc.getApplication().getNavigationHandler(); nh.handleNavigation(fc, "*", "logout"); }

else { String currentPage = view.getViewId(); boolean isLoginPage = currentPage.indexOf("login") > -1 || currentPage.indexOf("teste") > -1 || currentPage.indexOf("confirmacaoChave") > -1; HttpSession session = (HttpSession) fc.getExternalContext().getSession(false); Usuario usuario = (Usuario) session.getAttribute("usuario"); if (!isLoginPage && (usuario == null || usuario.getNome() == null))

{ NavigationHandler nh = fc.getApplication().getNavigationHandler(); nh.handleNavigation(fc, "*", "logout"); }

} } catch (Exception e)

{ e.printStackTrace(); NavigationHandler nh = fc.getApplication().getNavigationHandler(); nh.handleNavigation(fc, "*", "logout"); }

}

@Override public PhaseId getPhaseId()

{ return PhaseId.RESTORE_VIEW; }

}

Also, this config worked fine in GF 3.0.1 to show a expired page for user, and it doesn't work with GF 3.1:

javax.enterprise.context.NonexistentConversationException /expired.html org.jboss.weld.context.NonexistentConversationException /expired.html javax.faces.application.ViewExpiredException /expired.html

Environment

Linux Fedora 12, kernel 2.6.32, NetBeans 7.0 RC1, GlassFish 3.1, Mojarra 2.1.0, Weld 1.1

Affected Versions

[2.1.0]

ren-zhijun-oracle commented 6 years ago
ren-zhijun-oracle commented 13 years ago

@javaserverfaces Commented Reported by edilmar

ren-zhijun-oracle commented 13 years ago

@javaserverfaces Commented rogerk said: triage. Thanks for the code sample.

ren-zhijun-oracle commented 11 years ago

@javaserverfaces Commented @manfredriem said: Can you verify if this is still a problem on the latest 2.1 release?

ren-zhijun-oracle commented 11 years ago

@javaserverfaces Commented edilmar said: There is a workaround in Forum link http://www.java.net/forum/topic/glassfish/glassfish/gf31-nullpointerexception-navigationhandlerimpl?force=399. I have used it with GF3.1 and GF3.1.1.

PS: I don't use GF3.2.x because other problems.

ren-zhijun-oracle commented 11 years ago

@javaserverfaces Commented @manfredriem said: Can you verify if it is a problem with the latest 2.1.20 release?

ren-zhijun-oracle commented 11 years ago

@javaserverfaces Commented edilmar said: I can't test for now in new versions of GlassFish. My project is in production with 3.1.1 version, and I use JSF implementation Mojarra v2.1.3-FCS. But I used the workaround above.

ren-zhijun-oracle commented 11 years ago

@javaserverfaces Commented @manfredriem said: Why don't you use 3.1.2.2? Can you manually patch your 3.1.1 with a later version of Mojarra to verify it works?

ren-zhijun-oracle commented 11 years ago

@javaserverfaces Commented @manfredriem said: Lowering priority because of no response

ren-zhijun-oracle commented 11 years ago

@javaserverfaces Commented @manfredriem said: Lowering priority because of no response

ren-zhijun-oracle commented 11 years ago

@javaserverfaces Commented @manfredriem said: Closing because of inactivity

ren-zhijun-oracle commented 7 years ago

@javaserverfaces Commented This issue was imported from java.net JIRA JAVASERVERFACES-2019

ren-zhijun-oracle commented 11 years ago

@javaserverfaces Commented Marked as incomplete on Monday, November 4th 2013, 5:37:25 am