Topic
6 replies Latest Post - ‏2013-09-26T14:09:52Z by msoucy
msoucy
msoucy
332 Posts
ACCEPTED ANSWER

Pinned topic View /index.faces could not be restored

‏2013-06-10T17:31:41Z |

I have an EGL JSF application which I recently migrated to RBD 8.5 and WAS Express 8.5 from RBD 8.0 and WAS Express 6.1. When I run the application within RBD using the WAS 8.5 test environment everything works fine. However, when I run the application off our IBM i5 using WAS Express 8.5 I get an error saying, "The website cannot display the page". The application contains a button that the user can press to display an HTML link. The link is to an external BIRT report. In the link is a parameter that is passed (employee #). At this point the user can click on the HTML link to open up a BIRT report in another window. Here is where the application fails. The minute you click on the HTML link and then try to go back to the application to do something else the error occurs. When I check the log files on WAS I see an error that states the following:

 

E com.ibm.ws.webcontainer.servlet.ServletWrapper service SRVE0014E: Uncaught service() exception root cause Faces Servlet: javax.servlet.ServletException: viewId:/index.faces - View /index.faces could not be restored.

 

What does this mean and does anyone have any idea how I fix this?

 

  • PengFeiYu
    PengFeiYu
    29 Posts
    ACCEPTED ANSWER

    Re: View /index.faces could not be restored

    ‏2013-08-22T07:56:18Z  in response to msoucy

    If you are using SUN RI 1.2 in WAS 8.5, can you try adding the following parameter in web.xml, then redeploy the web application to WAS?

    <context-param>
       <param-name>com.sun.faces.enableRestoreView11Compatibility</param-name>
       <param-value>true</param-value>
    </context-param>

    • msoucy
      msoucy
      332 Posts
      ACCEPTED ANSWER

      Re: View /index.faces could not be restored

      ‏2013-08-23T20:15:51Z  in response to PengFeiYu

      I tried your suggestion and it did not work.  It's weird, after I click on the link and go back to my program and click on a button to run a function within my EGL program is loses the values I have stored in my session variables.  On the JSF page I have a combo box with choices in the drop down menu.  After I click the button to run my function the combo box goes empty and nothing happens.  Very strange.

      • PengFeiYu
        PengFeiYu
        29 Posts
        ACCEPTED ANSWER

        Re: View /index.faces could not be restored

        ‏2013-08-30T08:06:35Z  in response to msoucy

        Hi,

        I invested it more, it looks like the session is expired due to invalidate or timeout or some other reasons. Not sure if you have explicitly set the session-timeout in web.xml or leave the web page untouched for a long time(30 minutes by default?).  When javax.faces.STATE_SAVING_METHOD is set to server, the ViewExpiredException will be thrown if  a POST request is made by clicking the command button/command link but the view state no longer exists in the session.

        It is suggested to gracefully handle the exception if the session is expired. You may need to add error-page to web.xml to redirect to a specific session expired web page (you can even to redirect to a login or index page). For example:

        <error-page>
             <exception-type>javax.faces.application.ViewExpiredException</exception-type>
             <location>/sessionExpried.jsp</location>
        </error-page>

        I also saw some other solutions to handle the exception such as rewriting the LifeCycle, ExceptionHandler or PhaseListener, but I think error-page should work well here.

        However, as far as I know, the ViewExpiredException may be caused by other reasons, instead of the session expiration. For example, the view number exceeds the max view numbers (by default, 15 for SUN RI and 20 for MyFaces) configured in web.xml; for some browsers, the page could be retried from the browser cache rather than the server side, which can also result in such ViewExpiredException.  In that case, I think the behavior is not expected and we may want to prevent the exception.

        Not sure if you're using SUN RI or MyFaces under WAS 8.5, I tried some of the solutions below, it works for me, hope they are helpful for you.

        For SUN RI:

        1. Change javax.faces.STATE_SAVING_METHOD from server(default value) to client.

        2. If for some reason the option 1 can not be used (usually for performance reason), then add the following context-parameter to web.xml:

            <context-param>
                <param-name>com.sun.faces.numberOfViewsInSession</param-name>
                <param-value>500</param-value> //Increase the number, I set to 500 in my case
            </context-param>
            <context-param>
                <param-name>com.sun.faces.numberOfLogicalViews</param-name>
                <param-value>500</param-value>//Increase the number, I set to 500 in my case
            </context-param>
            <context-param>
                <param-name>com.sun.faces.enableRestoreView11Compatibilty</param-name>
                <param-value>true</param-value>
            </context-param>

        3. Implement the web filter to change the HTTP response header in order to notify the browser DO NOT cache the web page.

            public void doFilter(ServletRequest request, ServletResponse response, FilterChain chain) throws IOException, ServletException {
                HttpServletResponse resp = (HttpServletResponse) response;
                resp.setHeader("Cache-Control", "no-cache, no-store, must-revalidate");
                resp.setHeader("Pragma", "no-cache");
                resp.setDateHeader("Expires", 0);
                chain.doFilter(request, resp);
            }

        then register the filter into web.xml:

            <filter>
                <display-name>MyFilter</display-name>
                <filter-name>MyFilter</filter-name>
                <filter-class>filters.MyFilter</filter-class>
            </filter>
            <filter-mapping>
                <filter-name>MyFilter</filter-name>
                <url-pattern>*.faces</url-pattern>
            </filter-mapping>
            <filter-mapping>
                <filter-name>MyFilter</filter-name>
                <url-pattern>/faces/*</url-pattern>
            </filter-mapping>

        4. Clear up the browser cache

        5. Deploy web application to WAS 8.5

         

        For MyFaces:

        1. Change javax.faces.STATE_SAVING_METHOD from server(default value) to client.

        2. If for some reason the option 1 can not be used (usually for performance reason), then add the following context-parameter to web.xml:

            <context-param>
                <param-name>org.apache.myfaces.NUMBER_OF_VIEWS_IN_SESSION</param-name>
                <param-value>500</param-value> //Increase the number, I set to 500 in my case
            </context-param>

        3. Implement the web filter to change the HTTP response header in order to notify the browser DO NOT cache the web page.

            public void doFilter(ServletRequest request, ServletResponse response, FilterChain chain) throws IOException, ServletException {
                HttpServletResponse resp = (HttpServletResponse) response;
                resp.setHeader("Cache-Control", "no-cache, no-store, must-revalidate");
                resp.setHeader("Pragma", "no-cache");
                resp.setDateHeader("Expires", 0);
                chain.doFilter(request, resp);
            }

        then register the filter into web.xml:

            <filter>
                <display-name>MyFilter</display-name>
                <filter-name>MyFilter</filter-name>
                <filter-class>filters.MyFilter</filter-class>
            </filter>
            <filter-mapping>
                <filter-name>MyFilter</filter-name>
                <url-pattern>*.faces</url-pattern>
            </filter-mapping>
            <filter-mapping>
                <filter-name>MyFilter</filter-name>
                <url-pattern>/faces/*</url-pattern>
            </filter-mapping>

        4. Clear up the browser cache

        5. Deploy web application to WAS 8.5

         

        To check which JSF implementation you are using, or change the implementation, you can go to Applications > Application Types > WebSphere enterprise applications > application_name > JSP and JSF options, then check or change the implementation from the combobox.

        I hope this helpful for you, also leave this question open in case somebody else have a best practice to handle such problem.

  • msoucy
    msoucy
    332 Posts
    ACCEPTED ANSWER

    Re: View /index.faces could not be restored

    ‏2013-09-26T13:54:37Z  in response to msoucy

    Just wanted to let everyone know I finally figured out what the source of the problem was.  The application that I was having troubles with had links to external BIRT reports.  The BIRT reports were on a different WAS profile.  When I changed the links to the BIRT reports to be on the same profile (port) as the EGL application the problem went away.

    • markevans
      markevans
      2612 Posts
      ACCEPTED ANSWER

      Re: View /index.faces could not be restored

      ‏2013-09-26T14:04:12Z  in response to msoucy

      Thanks for letting the forum folks know.

      • msoucy
        msoucy
        332 Posts
        ACCEPTED ANSWER

        Re: View /index.faces could not be restored

        ‏2013-09-26T14:09:52Z  in response to markevans

        Your welcome.  I just can't believe it was something as simple as changing the URL links in my application. I only wish I had thought of that sooner.