Reputation: 16982
I have an application built using JSF1.2. I have a home page which has a set of command links. After I deploy the application , when open the home page and click on any of these menu links - I get the below exception. However if I navigate to other pages and come back to page and click on any of the links , the approperiate page is opening.
javax.faces.application.ViewExpiredException: viewId:/home/home.jsf - View /home/home.jsf could not be restored.
web.xml has the below filter -
<filter>
<filter-name>Seam Filter</filter-name>
<filter-class>org.jboss.seam.servlet.SeamFilter</filter-class>
<init-param>
<param-name>createTempFiles</param-name>
<param-value>false</param-value>
</init-param>
<init-param>
<param-name>maxRequestSize</param-name>
<param-value>100000</param-value>
</init-param>
</filter>
<filter-mapping>
<filter-name>Seam Filter</filter-name>
<servlet-name>Faces Servlet</servlet-name>
<dispatcher>FORWARD</dispatcher>
<dispatcher>REQUEST</dispatcher>
<dispatcher>INCLUDE</dispatcher>
<dispatcher>ERROR</dispatcher>
</filter-mapping>
Upvotes: 0
Views: 2345
Reputation: 938
This is not a bug - it's a feature of JSF. THis occurs when your page is idle for some time, so the view expires. There are plenty of workarounds for this. Try reading this very good post: JSF Odyssey – ViewExpiredException
Hope it helps.
Upvotes: 1
Reputation: 1108577
That can happen if the page is actually loaded from browser's cache, or if your web application is somewhere invalidating the session after the response of the very first request. Since the latter is a rather odd programming approach, I suspect that it's just the browser cache. You'd need to create a filter to tell the browser to not cache the JSF requests. The filter should be mapped on <servlet-name>
of the FacesServlet
and do the following job in doFilter()
method:
@Override
public void doFilter(ServletRequest request, ServletResponse response, FilterChain chain) throws IOException, ServletException {
HttpServletResponse res = (HttpServletResponse) response;
res.setHeader("Cache-Control", "no-cache, no-store, must-revalidate"); // HTTP 1.1.
res.setHeader("Pragma", "no-cache"); // HTTP 1.0.
res.setDateHeader("Expires", 0); // Proxies.
chain.doFilter(request, response);
}
Don't forget to clear the browser cache before testing the webapp with the new filter.
Unrelated to the concrete problem, you've there a major design problem: you're using command links to perform page-to-page navigation. There they are not for. Command links are to be used for form submits. You should be using <h:outputLink>
or normal HTML <a>
elements for page-to-page navigation. This way the pages will be bookmarkable, searchbot-indexable and the URL in browser address bar will not anymore be "one step behind". See also When should I use h:outputLink instead of h:commandLink?
Upvotes: 2