• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Tim Cooke
  • paul wheaton
  • Liutauras Vilda
  • Ron McLeod
Sheriffs:
  • Jeanne Boyarsky
  • Devaka Cooray
  • Paul Clapham
Saloon Keepers:
  • Scott Selikoff
  • Tim Holloway
  • Piet Souris
  • Mikalai Zaikin
  • Frits Walraven
Bartenders:
  • Stephan van Hulst
  • Carey Brown

Problem in redirecting to the index screen

 
Greenhorn
Posts: 17
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi All,

I have a filter in which I redirect the screen to login page, if the url is directly pasted in the browser. It works fine but when the application is in use and suddenly user pastes the URL in the browser of index page, I need to clear some faces session values and redirect the screen to login and in the else part of my code I am not able to get the handle of facesContext (To clear the Backing bean values).

Pls advice me. Any better approach to redirect to the index screen is welcome.

public void doFilter(ServletRequest req, ServletResponse res,
FilterChain filterChain) throws IOException, ServletException {

if ((req instanceof HttpServletRequest)
&& (res instanceof HttpServletResponse)) {
HttpServletRequest request = (HttpServletRequest) req;
if (request.getMethod().equals("GET")) {
if (!request.getRequestURL().toString().equals(
"LoginScreen")) {
request.getSession().invalidate();
((HttpServletResponse) res)
.sendRedirect("LoginScreen");
return;
}
} else {
//FacesContext.getCurrentInstance() returns me null
}
}

filterChain.doFilter(req, res);
}
 
Greenhorn
Posts: 9
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
You can not access FacesContext in a Servlet or a Filter. It will always be null. If you want to access it anyways, take a look at http://balusc.blogspot.com/2006/06/communication-in-jsf.html.

Another way of doing it is try accessing your bean directly. looks like you have session scoped bean, so you can simply get it from the session by doing session.getAttribute("managedBeanName"); and then you can do whatever you want with this object.
 
Manohar Chhapolia
Greenhorn
Posts: 17
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
The blog is really useful for a beginner like me.
Thanks a lot Nitin.
 
She'll be back. I'm just gonna wait here. With this tiny ad:
New web page for Paul's Rocket Mass Heaters movies
https://coderanch.com/t/785239/web-page-Paul-Rocket-Mass
reply
    Bookmark Topic Watch Topic
  • New Topic