wood burning stoves
The moose likes JSF and the fly likes Handling the Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login

JavaRanch » Java Forums » Java » JSF
Bookmark "Handling the "View Cannot be restored" error message" Watch "Handling the "View Cannot be restored" error message" New topic

Handling the "View Cannot be restored" error message

Kumar Saravanan
Ranch Hand

Joined: Aug 25, 2004
Posts: 40

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.

Kumar Saravanan
Jignesh Patel
Ranch Hand

Joined: Nov 03, 2001
Posts: 626

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(""))) {

//deliver request to next filter
chain.doFilter(request, response);
Kumar Saravanan
Ranch Hand

Joined: Aug 25, 2004
Posts: 40
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.

Kumar Saravanan
I’ve looked at a lot of different solutions, and in my humble opinion Aspose is the way to go. Here’s the link: http://aspose.com
subject: Handling the "View Cannot be restored" error message
It's not a secret anymore!