Showing posts with label JSF. Show all posts
Showing posts with label JSF. Show all posts

Tuesday 30 September 2014

How to solve JSF issue view could not be restored

Log Error : - javax.servlet.ServletException: viewId:/mysettings/myinvoiceTemplates/BillingTemplate.html - View /mysettings/myinvoiceTemplates/BillingTemplate.html could not be restored.

Issue : - Sometimes when we open a JSF page in the application and then open some other page in new tab with right clicking on the existing page and work on new opened page for 2 or 3 minute. When we come back to the earlier page after 2 or 3 minutes and click on any button then we get this error in log that page could not be restored.

Solution : -  It can be solved with two ways as below:
1). By default JSF store the state of the page at server side. We can change this to client by changing context parameter “state_saving_method” in web.xml  as:
<context-param>
       <param-name>javax.faces.STATE_SAVING_METHOD</param-name>
       <param-value>client</param-value>
</context-param>

After changing the method to client, the state of the page is saved in a input hidden field at client side with the page. This will solve the above problem.
Advantage :-
Lower the terrific to server because for page state container does not need to go to client side.
Disadvantage : - This can lead to more data download when we open the page because now page state is also stored at client side.

2). Add one more context parameter in Web.xml file. It will re-create/restore the expired view.

<context-param> 

      <param-name>com.sun.faces.enableRestoreView11Compatibility</param-name>   

      <param-value>true</param-value> 

</context-param>