He must have forgotten to give it to you. It's from the wiki. :)
/**
* Allows to get FacesContext outside of a faces request.
*/
protected FacesContext getFacesContext(HttpServletRequest request,
HttpServletResponse response) {
FacesContext facesContext = FacesContext.getCurrentInstance();
if (facesContext == null) {
FacesContextFactory contextFactory =
(FacesContextFactory)FactoryFinder.getFactory(FactoryFinder.FACES_CONTEXT_FACTORY);
LifecycleFactory lifecycleFactory =
(LifecycleFactory)FactoryFinder.getFactory(FactoryFinder.LIFECYCLE_FACTORY);
Lifecycle lifecycle =
lifecycleFactory.getLifecycle(LifecycleFactory.DEFAULT_LIFECYCLE);
facesContext =
contextFactory.getFacesContext(request.getSession().getServletContext(),
request, response, lifecycle);
/*
// set a new viewRoot, otherwise context.getViewRoot
returns null
UIViewRoot view =
facesContext.getApplication().getViewHandler().createView(facesContext, "");
facesContext.setViewRoot(view);
*/
}
return facesContext;
}
I have this function defined in my security filter. The filter works
great for redirection both on timeout and unauthorized pages.
Regards,
Jeff Bischoff
Kenneth L Kurz & Associates, Inc.
Thomas Chang wrote:
Hi,
I tryed your code but I got compile error by:
FacesContext lContext = getFacesContext(pRequest, pResponse);
Here is the error message:
"The method getFacesContext(ServletRequest, ServletResponse) is undefined"
Regards
Thomas
Veit Guna <[EMAIL PROTECTED]> schrieb: Your web.xml looks ok to me, although my
url-pattern begins with "/".
I've something like this in my working Filter:
public void doFilter(ServletRequest pRequest, ServletResponse
pResponse, FilterChain pChain) throws IOException, ServletException {
HttpServletRequest lRequest = (HttpServletRequest) pRequest;
if (! lRequest.isRequestedSessionIdValid() &&
lRequest.getRequestedSessionId() != null) {
log.debug("invalidated session detected!");
FacesContext lContext = getFacesContext(pRequest, pResponse);
lRequest.getSession().invalidate();
lRequest.getSession(true);
lContext.getApplication().getNavigationHandler().handleNavigation(lContext,
null, "session_expired");
} else {
pChain.doFilter(pRequest, pResponse);
}
}
The "session_expired" is the normal jsf outcome.
I hope that helps.
Veit
Thomas Chang schrieb:
Hi,
I do following:
1.
set filter in web.xml as follow:
sessionExpiredFilter
my.utils.SessionExpiredFilter
...
sessionExpiredFilter
*.jsf
2.
And here is my filter class:
public class SessionExpiredFilter {
private String page = "/jsp/login/login.xhtml";
public void destroy() {
}
public void doFilter(ServletRequest request, ServletResponse response,
FilterChain chain) throws IOException, ServletException {
if (((HttpServletRequest) request).getRequestedSessionId() != null
&& ((HttpServletRequest) request).isRequestedSessionIdValid() ==
false) {
RequestDispatcher rd = request.getRequestDispatcher(page);
rd.forward(request, response);
} else {
chain.doFilter(request, response);
}
}
public void init(FilterConfig filterConfig) throws ServletException {
if (filterConfig.getInitParameter("page") != null) {
page = filterConfig.getInitParameter("page");
}
}
}
But it doesn't work. If the timeout comes, it dosen't redirect.
Could you please show me your filter class?
Regards
Thomas
*/Veit Guna /* schrieb:
Hi.
Yes, I use a filter to handle session-timedout requests. The next
time an invalidated session is requested, a redirect will be done.
Regards,
Veit
-------- Original-Nachricht --------
Datum: Tue, 13 Mar 2007 15:11:45 +0100 (CET)
Von: Thomas Chang
An: [email protected]
CC:
Betreff: Question about redirection on timeout
> Hi all,
>
> I set the timeout in the web.xml and it works find. What I want
now is: if
> the timeout comes, it redirects to the login.xhtml. How can I do that?
> Seems I have to rewrite the filter?
>
> Regards
>
> Thomas
>
>
> ---------------------------------
> Was Sie schon immer wissen wollten aber nie zu Fragen trauten? Yahoo!
> Clever hilft Ihnen.
--
"Feel free" - 5 GB Mailbox, 50 FreeSMS/Monat ...
Jetzt GMX ProMail testen: www.gmx.net/de/go/mailfooter/promail-out
------------------------------------------------------------------------
Der neue Internet Explorer 7 in deutscher Ausführung ist da
!
---------------------------------
Was Sie schon immer wissen wollten aber nie zu Fragen trauten? Yahoo! Clever
hilft Ihnen.