File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
Win a copy of Clojure in Action this week in the Clojure forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Handling the "View Cannot be restored" error message

 
Kumar Saravanan
Ranch Hand
Posts: 40
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,

I used ajax4jsf in my UI to refresh some component.

If I get any exception while processing the ajax call how do I catch that exception in UI side? For example, If the user session is timed out after a specific amount of time, If I hit my ajax enabled link then I am getting exception like "View Cannot be restored"...

Could you please advice how do I catch that exception and handle it appropriately.

Thanks,
Kumar Saravanan
 
Jignesh Patel
Ranch Hand
Posts: 626
Mac
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Session time out has nothing to do with your UI side.

So when the user hits link request goes to server and since server is not able to find jsessionid information it throws error.

So you need to use Filter API add a filter class and put following code:

/** Creates a new instance of SecurityCheckFilter */
public void doFilter(ServletRequest request, ServletResponse response, FilterChain chain)
throws IOException, ServletException {

HttpServletRequest hreq = (HttpServletRequest)request;
HttpServletResponse hres = (HttpServletResponse)response;
HttpSession session = hreq.getSession();

String checkforloginpage = hreq.getPathTranslated();

//dont filter login.jsp because otherwise an endless loop.
//& only filter .jsp otherwise it will filter all images etc as well.
if ((request.getAttribute(FILTER_APPLIED) == null)&&(!checkforloginpage.endsWith("login.jsp"))&&(checkforloginpage.endsWith(".jsp"))) {
request.setAttribute(FILTER_APPLIED, Boolean.TRUE);

//If the session bean is not null get the session bean property username.
String user=null;
if(((toll.SessionBean1)session.getAttribute("SessionBean1"))!=null) {
user = ((toll.SessionBean1)session.getAttribute("SessionBean1")).getUsername();
}

if((user==null)||(user.equals(""))) {
hres.sendRedirect("login.jsp");
return;
}

}
//deliver request to next filter
chain.doFilter(request, response);
}
 
Kumar Saravanan
Ranch Hand
Posts: 40
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
OK. I got it...but sometimes if I get any exception while fetching the value from the database or during the data conversion, am getting the same exception. How do I handle that kind of exception and give user a friendly error page instead of showing the "View cannot be restored"

Thanks for your reply.

Regards,
Kumar Saravanan
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic