14 Replies Latest reply on Jul 10, 2009 9:00 AM by Rajneesh Kumar

    ViewExpiredException: Possibly found the exact problem and n

    Rajneesh Kumar Newbie

      We recently upgraded Rich Faces to 3.3.0 along with my faces 1.2.6.

      We were facing a problem that if we access the application first time, first page does not work but there after same set of pages work fine. Please see what we found in this.

      Initial configurations were as follows..
      javax.faces.STATE_SAVING_METHOD=server
      org.apache.myfaces.NUMBER_OF_VIEWS_IN_SESSION = 4

      Always, if we use new browser / (Clean browser cache) and login into application first page is rendered properly. But, if we click any of the link on this page then ViewExpiredException is thrown because in the post back request required view id is not available in the server cached views list.

      I debug the code and found couple of facts,

      1) AjaxStateHolder class uses ContextInitParameters class to rely on the no. of views to store in a session and expects a new context param 'com.sun.faces.numberOfViewsInSession' to be declare in the web.xml.

      Now, we can explains what happens is while doing login browser sends up lots of request to server for page as well as for every image which is being displayed, or style sheets or js files etc.

      And, sever stores up each request generated view in the same 'views' list which it is holding for pages. So, images etc are replacing the page view in the list for the first time as there were around total 25 requests are generating in our case for the cleaned browser.

      After this, we do login second time browser does not send separate requests for images and css, and pages works fine because only one views get stored and it is available when it is required.

      Proposed Solution 1:

      I am not sure, why AjaxStateHolder is storing every resource generated view in the same views list. Request, which are made for images, css and scripts should not be stored in the views state map.

      Is this correct to store images, css and scripts in the same view state map or can I put a check on this chunk of code not to put images, css and scripts in the AjaxStateHolder view state map ? .

      If it is really not required to store images, css and scripts in the same view state map, this will solve our problem completely.

      Well, I didn't check the old version code for myfaces how it was handling this, whether it was storing the images and css etc in the same view state map or not but we never faced this problem in older version of my faces and rich faces.


      Proposed Solution 2 [Temporarily]: I can set up com.sun.faces.numberOfViewsInSession variable to a high no. i.e. 25 which is the exact in our case and it will work fine. But, if I increase any image on the same first page. This problem could again in front of us.






        • 1. Re: ViewExpiredException: Possibly found the exact problem a
          Juan Gonzalez Newbie

          After 3 years testing for getting the best solution for this, best option for me is :

          javax.faces.STATE_SAVING_METHOD=client

          and all problems about ViewExpiredException went away.

          • 3. Re: ViewExpiredException: Possibly found the exact problem a
            Rajneesh Kumar Newbie

             

            "juangon" wrote:
            After 3 years testing for getting the best solution for this, best option for me is :

            javax.faces.STATE_SAVING_METHOD=client

            and all problems about ViewExpiredException went away.


            Yes, I agree that using the Client will solve this problem at all. But, I do want to keep the state saving method as server as it has other benefits and in past we have change this to server deliberately.

            Actually, I am looking for the problem that as I found above rich faces class throws an exception in case if view is not found for a post back request, but myfaces original class does not throw an exception instead it creates a view in this case.

            So, more or less either exception should not be thrown because no. of views are limited as those can be configured or these possible irrelevant views i.e. for images or css should not be kept in the same map which for actual page views if I am correct. please provide your views.

            • 4. Re: ViewExpiredException: Possibly found the exact problem a
              Nick Belaevski Master

              I've tested this - only pages views are contained in AjaxStateHolder; nothing about CSS/scripts. Can you please post debugger screenshot?

              • 5. Re: ViewExpiredException: Possibly found the exact problem a
                Rajneesh Kumar Newbie

                I don't know how to attach a screen shot here directly with an image. Any just copying the contents of the views map from AjaxStateHolder class. This is actual map which I inspected after login into application for the first click on a link for the first page.

                ----------------
                "views"=LRUMap<K,V> ...
                ...
                {/index.jsp={j_id1=org.ajax4jsf.application.AjaxStateHolder$StateReference@f6816d}, /ProjectsListing.jsp={j_id2=org.ajax4jsf.application.AjaxStateHolder$StateReference@1ab26e2}, /script/UtilityJavaScript.js={j_id3=org.ajax4jsf.application.AjaxStateHolder$StateReference@185c87d}, /resources/stylesheet.css={j_id4=org.ajax4jsf.application.AjaxStateHolder$StateReference@2dc5e6}, /images/Claimkey-30-Spot.jpg={j_id5=org.ajax4jsf.application.AjaxStateHolder$StateReference@11b8549}, /css/common.css={j_id6=org.ajax4jsf.application.AjaxStateHolder$StateReference@1cb8465}, /script/Header.js={j_id7=org.ajax4jsf.application.AjaxStateHolder$StateReference@611645}, /admin/styles/standard.css={j_id8=org.ajax4jsf.application.AjaxStateHolder$StateReference@1fd374a}, /images/bg_gray.gif={j_id9=org.ajax4jsf.application.AjaxStateHolder$StateReference@138f4e9}, /images/tab_gray_right_active.gif={j_id10=org.ajax4jsf.application.AjaxStateHolder$StateReference@5721f0}, /images/tab_gray_left_active.gif={j_id11=org.ajax4jsf.application.AjaxStateHolder$StateReference@753ab7}, /images/tab_gray_left.gif={j_id12=org.ajax4jsf.application.AjaxStateHolder$StateReference@61fc02}, /images/tab_gray_right.gif={j_id13=org.ajax4jsf.application.AjaxStateHolder$StateReference@e7e98d}, /images/redImage.gif={j_id14=org.ajax4jsf.application.AjaxStateHolder$StateReference@1964738}, /images/exclamation.jpg={j_id15=org.ajax4jsf.application.AjaxStateHolder$StateReference@11dbcb4}, /images/icons/patent_list.png={j_id16=org.ajax4jsf.application.AjaxStateHolder$StateReference@150097d}, /images/icons/mapping_report.png={j_id17=org.ajax4jsf.application.AjaxStateHolder$StateReference@19f28b0}, /images/halfGreenImage.gif={j_id18=org.ajax4jsf.application.AjaxStateHolder$StateReference@2840c5}, /images/icons/change_default_ontology.png={j_id19=org.ajax4jsf.application.AjaxStateHolder$StateReference@b48638}, /images/fullGreenImage.gif={j_id20=org.ajax4jsf.application.AjaxStateHolder$StateReference@1d7c8f1}, /images/icons/claim_map.png={j_id21=org.ajax4jsf.application.AjaxStateHolder$StateReference@1c97b7a}, /images/bg_footer.jpg={j_id22=org.ajax4jsf.application.AjaxStateHolder$StateReference@c98a94}}

                • 6. Re: ViewExpiredException: Possibly found the exact problem a
                  Nick Belaevski Master

                  How do you add images and CSS files to the page? Do you use XCSS or no?

                  • 7. Re: ViewExpiredException: Possibly found the exact problem a
                    Rajneesh Kumar Newbie

                     

                    "nbelaevski" wrote:
                    How do you add images and CSS files to the page? Do you use XCSS or no?


                    We have xml and html both type of jsps in the application. Please see following is the code for one of the image which was used on the 'ProjectListing.jsp', you can see map is holding the view for this jsp and for the used image also.


                    --------- Image usage ---
                    <h:graphicImage id="imgMappingStatusIncomplete" title="Mark mapping as out dated"
                    rendered="#{ProjectsListing.incompleteStatus}" value="images/halfGreenImage.gif"/>
                    ---------

                    This is piece of code of how we add stylesheets to our pages..
                    ----- Style sheet linking ----

                    -----

                    And also note as I already stated that browser sends the request to the server for the images only if browse cache is cleaned, and if we visited this page again then request for this image is not send to the server so further image view will not be cached and the existing cached view for this image will just get override because of new page views and things are fine.

                    • 8. Re: ViewExpiredException: Possibly found the exact problem a
                      Rajneesh Kumar Newbie

                       

                      "nbelaevski" wrote:
                      How do you add images and CSS files to the page? Do you use XCSS or no?


                      Adding response again, as style sheet related code section was not shown properly.


                      We have xml and html both type of jsps in the application. Please see following is the code for one of the image which was used on the 'ProjectListing.jsp', you can see map is holding the view for this jsp and for the used image also.


                      --------- Image usage ---
                      <h:graphicImage id="imgMappingStatusIncomplete" title="Mark mapping as out dated"
                      rendered="#{ProjectsListing.incompleteStatus}" value="images/halfGreenImage.gif"/>

                      ---------

                      This is piece of code of how we add stylesheets to our pages..
                      ----- Style sheet linking and scripts ----
                      <link href="resources/stylesheet.css" rel="stylesheet" type="text/css" />

                      <script language="javaScript" src="script/UtilityJavaScript.js">
                       var abc=null;
                       </script>

                      -----

                      And also note as I already stated that browser sends the request to the server for the images only if browse cache is cleaned, and if we visited this page again then request for this image is not send to the server so further image view will not be cached and the existing cached view for this image will just get override because of new page views and things are fine.

                      • 9. Re: ViewExpiredException: Possibly found the exact problem a
                        Nick Belaevski Master

                        Does anything change if you use

                        <h:graphicImage id="imgMappingStatusIncomplete" title="Mark mapping as out dated"
                        rendered="#{ProjectsListing.incompleteStatus}" value="/images/halfGreenImage.gif"/>
                        not relative, but absolute image path? I guess the problem happens because your Faces Servlet is prefix-mapped, so all relative resources are served through it. How does web.xml look like?

                        • 10. Re: ViewExpiredException: Possibly found the exact problem a
                          Rajneesh Kumar Newbie

                           

                          "nbelaevski" wrote:
                          Does anything change if you use
                          <h:graphicImage id="imgMappingStatusIncomplete" title="Mark mapping as out dated"
                          rendered="#{ProjectsListing.incompleteStatus}" value="/images/halfGreenImage.gif"/>
                          not relative, but absolute image path? I guess the problem happens because your Faces Servlet is prefix-mapped, so all relative resources are served through it. How does web.xml look like?


                          Well, I would not prefer the absolute path because we have separate instance (more than one webapps) running for the same code base.

                          Will that matter in this case? I am not sure. Yes, it is solve our problem we can think of the other ways to use that.

                          What do you say about scripts and stylesheet, why they are being cached in the view state map?




                          Please check configuration in web.xml, we have mapped the rich faces and faces servlet as follows..

                          <filter>
                           <display-name>RichFaces Filter</display-name>
                           <filter-name>richfaces</filter-name>
                           <filter-class>org.ajax4jsf.Filter</filter-class>
                           </filter>
                           <filter-mapping>
                           <filter-name>richfaces</filter-name>
                           <servlet-name>Faces Servlet</servlet-name>
                           <dispatcher>REQUEST</dispatcher>
                           <dispatcher>FORWARD</dispatcher>
                           <dispatcher>INCLUDE</dispatcher>
                           </filter-mapping>
                          
                           <filter>
                           <filter-name>MyFacesExtensionsFilter</filter-name>
                           <filter-class>
                           org.apache.myfaces.webapp.filter.ExtensionsFilter
                           </filter-class>
                           <init-param>
                           <param-name>maxFileSize</param-name>
                           <param-value>40m</param-value>
                           </init-param>
                           <init-param>
                           <param-name>uploadThresholdSize</param-name>
                           <param-value>100k</param-value>
                           </init-param>
                           </filter>
                           <filter-mapping>
                           <filter-name>MyFacesExtensionsFilter</filter-name>
                           <url-pattern>/faces/*</url-pattern>
                           </filter-mapping>
                          
                           <!-- Faces Servlet -->
                           <servlet>
                           <servlet-name>Faces Servlet</servlet-name>
                           <servlet-class>
                           <!-- This is to handle errors in myfaces-->
                           claimmapping.common.faces.servlet.MyFacesServletWrapper
                           </servlet-class>
                           <load-on-startup> 1 </load-on-startup>
                           </servlet>
                          
                           <!-- Faces Servlet Mapping -->
                           <servlet-mapping>
                           <servlet-name>Faces Servlet</servlet-name>
                           <url-pattern>/faces/*</url-pattern>
                           </servlet-mapping>


                          Anything else that I should display from web.xml.



                          • 11. Re: ViewExpiredException: Possibly found the exact problem a
                            Rajneesh Kumar Newbie

                             

                            "nbelaevski" wrote:
                            Does anything change if you use
                            <h:graphicImage id="imgMappingStatusIncomplete" title="Mark mapping as out dated"
                            rendered="#{ProjectsListing.incompleteStatus}" value="/images/halfGreenImage.gif"/>
                            not relative, but absolute image path? I guess the problem happens because your Faces Servlet is prefix-mapped, so all relative resources are served through it. How does web.xml look like?


                            Well, I would not prefer the absolute path because we have separate instance (more than one webapps) running for the same code base.

                            Will that matter in this case? I am not sure. Yes, it is solve our problem we can think of the other ways to use that.

                            What do you say about scripts and stylesheet, why they are being cached in the view state map?




                            Please check configuration in web.xml, we have mapped the rich faces and faces servlet as follows..

                            <filter>
                             <display-name>RichFaces Filter</display-name>
                             <filter-name>richfaces</filter-name>
                             <filter-class>org.ajax4jsf.Filter</filter-class>
                             </filter>
                             <filter-mapping>
                             <filter-name>richfaces</filter-name>
                             <servlet-name>Faces Servlet</servlet-name>
                             <dispatcher>REQUEST</dispatcher>
                             <dispatcher>FORWARD</dispatcher>
                             <dispatcher>INCLUDE</dispatcher>
                             </filter-mapping>
                            
                             <filter>
                             <filter-name>MyFacesExtensionsFilter</filter-name>
                             <filter-class>
                             org.apache.myfaces.webapp.filter.ExtensionsFilter
                             </filter-class>
                             <init-param>
                             <param-name>maxFileSize</param-name>
                             <param-value>40m</param-value>
                             </init-param>
                             <init-param>
                             <param-name>uploadThresholdSize</param-name>
                             <param-value>100k</param-value>
                             </init-param>
                             </filter>
                             <filter-mapping>
                             <filter-name>MyFacesExtensionsFilter</filter-name>
                             <url-pattern>/faces/*</url-pattern>
                             </filter-mapping>
                            
                             <!-- Faces Servlet -->
                             <servlet>
                             <servlet-name>Faces Servlet</servlet-name>
                             <servlet-class>
                             <!-- This is to handle errors in myfaces-->
                             claimmapping.common.faces.servlet.MyFacesServletWrapper
                             </servlet-class>
                             <load-on-startup> 1 </load-on-startup>
                             </servlet>
                            
                             <!-- Faces Servlet Mapping -->
                             <servlet-mapping>
                             <servlet-name>Faces Servlet</servlet-name>
                             <url-pattern>/faces/*</url-pattern>
                             </servlet-mapping>


                            Anything else that I should display from web.xml.

                            • 12. Re: ViewExpiredException: Possibly found the exact problem a
                              Rajneesh Kumar Newbie

                               

                              Just correcting the above sentence which I mentioned in previous reply, Will absolute path help us not to cache the images in view state map? I am not sure. But Yes if it solves our problem we can think of the other ways to use that. What do you say about scripts and stylesheet, why they are being cached in the view state map?


                              • 13. Re: ViewExpiredException: Possibly found the exact problem a
                                Rajneesh Kumar Newbie

                                Hi All,
                                I have noticed one more thing is that we have mapped the Faces Servlet in web.xml with /faces/*, so typically it is treating every request is a normal JSF request and causing images, CSS to be cached in the same map which could be the actual cause of this problem in this latest release.

                                We should change the Faces Servlet mapping to either something /*.jsp. Lets do this change in 1.58 code base and find out if it solves the problem permanently.

                                • 14. Re: ViewExpiredException: Possibly found the exact problem a
                                  Rajneesh Kumar Newbie

                                  I actually mean not to use /faces/* as it also treats normal resources like images, css and scripts etc to be processed via JSF request.

                                  So, we will switch mapping to either *.jsf or *.faces, to avoid the problem which is being caused by images, CSS and scripts etc.

                                  I have verified *.faces mapping and now my same pages are working fine even I just have no. of views kept in session to only 4. Lots of gain in memory performance.

                                  Finally, my problem is solved.