Forums Register Login

java.lang.RuntimeException: Cannot find FacesContext

+Pie Number of slices to send: Send
I am getting this error after Session time i am automatically redirecting to this page.but it is throwing error in the jsp page..Any one knows the solution for this.Just help me.Thanks for reading this Post......

My jap page....yourSessionIsTimedOut.jsp

HTTP Status 500 -

--------------------------------------------------------------------------------

type Exception report

message

description The server encountered an internal error () that prevented it from fulfilling this request.

exception

org.apache.jasper.JasperException: An exception occurred processing JSP page /home/yourSessionIsTimedOut.jsp at line 12

9: </head>
10: <body class="bg_login">
11:
12: <h:form id="sessionTimeoutForm" >
13: <h1>Welcome, dude with a session!</h1>
14: Your session is expired.
15: <br>


Stacktrace:
org.apache.jasper.servlet.JspServletWrapper.handleJspException(JspServletWrapper.java:505)
org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:416)
org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:342)
org.apache.jasper.servlet.JspServlet.service(JspServlet.java:267)
javax.servlet.http.HttpServlet.service(HttpServlet.java:717)


root cause

java.lang.RuntimeException: Cannot find FacesContext
javax.faces.webapp.UIComponentClassicTagBase.getFacesContext(UIComponentClassicTagBase.java:1855)
javax.faces.webapp.UIComponentClassicTagBase.setJspId(UIComponentClassicTagBase.java:1672)
org.apache.jsp.home.yourSessionIsTimedOut_jsp._jspx_meth_h_005fform_005f0(yourSessionIsTimedOut_jsp.java:100)
org.apache.jsp.home.yourSessionIsTimedOut_jsp._jspService(yourSessionIsTimedOut_jsp.java:71)
org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:70)
javax.servlet.http.HttpServlet.service(HttpServlet.java:717)
org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:374)
org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:342)
org.apache.jasper.servlet.JspServlet.service(JspServlet.java:267)
javax.servlet.http.HttpServlet.service(HttpServlet.java:717)


note The full stack trace of the root cause is available in the Apache Tomcat/6.0.20 logs.


AppSession.java


public class AppSession {

/**
*
*/

private static Log log = LogFactory.getLog(AppSession.class);


public static void CreateNewSession(){

FacesContext facesContext = FacesContext.getCurrentInstance();
HttpSession session = (HttpSession) facesContext.getExternalContext(). getSession(true);
log.info("session id = "+ session.getId());

}

public static void AppTimeOut(){
log.info("AppTimeOut Setting...");
FacesContext facesContext = FacesContext.getCurrentInstance();
HttpSession session = (HttpSession) facesContext.getExternalContext().getSession(false);
session.setMaxInactiveInterval(10);

}

public static void AppSessionSetAttribute(String arg0, Object arg1){
log.debug("Session attribute setting.... " + arg0 + "=" + arg1);
FacesContext facesContext = FacesContext.getCurrentInstance();
HttpSession session = (HttpSession) facesContext.getExternalContext(). getSession(false);
session.setAttribute(arg0, arg1);
}

public static Object AppSessionGetAttribute(String arg0){
log.debug("Session attribute retrieve.... " + arg0 );
FacesContext facesContext = FacesContext.getCurrentInstance();
HttpSession session = (HttpSession) facesContext.getExternalContext().getSession(false);
if(session==null){
session.invalidate();
return null;
}
return session.getAttribute(arg0);
}


}

yourSessionIsTimedOut.jsp

<%@taglib prefix="f" uri="http://java.sun.com/jsf/core"%>
<%@taglib prefix="h" uri="http://java.sun.com/jsf/html"%>
<%@ taglib prefix="rich" uri="http://richfaces.org/rich" %>
<%@ taglib prefix="a4j" uri="http://richfaces.org/a4j"%>
<html>
<head>
<link href="../_assets/css/celcom.css" rel="stylesheet" type="text/css">
<title>SessionTimeout</title>
</head>
<body class="bg_login">

<h:form id="sessionTimeoutForm" >
<h1>Welcome, dude with a session!</h1>
Your session is expired.
<br>
Thank you for your cooperation!
<h:outputLink value="#{facesContext.externalContext.requestContextPath}/login.jsf"></h:outputLink>

</h:form>

</body>
</html>

SessionTimeoutPhaseListener.java

public class SessionTimeoutPhaseListener implements PhaseListener {

public void beforePhase(PhaseEvent event) {

FacesContext facesCtx = event.getFacesContext();
ExternalContext extCtx = facesCtx.getExternalContext();
HttpSession session = (HttpSession) extCtx.getSession(false);

boolean newSession = (session == null) || (session.isNew());
System.out.println("newSession:"+newSession);
boolean postback = !extCtx.getRequestParameterMap().isEmpty();
System.out.println("postback:"+postback);
boolean timedout = postback && newSession;
System.out.println("timedout:"+timedout);
if (timedout) {
Application app = facesCtx.getApplication();
ViewHandler viewHandler = app.getViewHandler();
UIViewRoot view = viewHandler.createView(facesCtx,
"yourSessionIsTimedOut.jsp");
facesCtx.setViewRoot(view);
System.out.println("view:"+view);
facesCtx.renderResponse();
try {
viewHandler.renderView(facesCtx, view);
facesCtx.responseComplete();
} catch (Throwable t) {
throw new FacesException("Session timed out", t);
}
}
}

public void afterPhase(PhaseEvent event) {
// Do nothing

}

public PhaseId getPhaseId() {
return PhaseId.RESTORE_VIEW;
}

public boolean isPostback(FacesContext context) {
return (!context.getExternalContext().getRequestParameterMap().isEmpty());
}
}




After session tome out it has to redirect to yourSessionIsTimedOut.jsp from there if i click login.jsf it has to redirect to login page........



Are you okay? You look a little big. Maybe this tiny ad will help:
a bit of art, as a gift, that will fit in a stocking
https://gardener-gift.com


reply
reply
This thread has been viewed 6556 times.
Similar Threads
Two MyFaces problems
Struts 1.2 Cannot find bean org.apache.struts.taglib.html.BEAN
I am so tired just getting start in jsf please help me please
Download file in JSF appliccation
session.isNew() always return true
More...

All times above are in ranch (not your local) time.
The current ranch time is
Mar 28, 2024 13:02:07.