0

Im using Mojarra 2.1.3, NetBeans 7.0.1, Primefaces 3.2.

I have a few dynamic xhtml pages backed by ViewScoped backing beans in my application. Each of the pages has p:dataTable which display List<> from the backing bean. The problem occurs when a user navigate to a different page with the details of each item in the datatable. Upon browing the detail information, a user will most likely hit on the browser back button to return to the list. And so I implemented a filter like this in my application.

    @Override
public void doFilter(ServletRequest request, ServletResponse response, FilterChain chain)
        throws IOException, ServletException {
    HttpServletRequest httpReq = (HttpServletRequest) request;
    HttpServletResponse httpRes = (HttpServletResponse) response;
    if (!httpReq.getRequestURI().startsWith(httpReq.getContextPath() + ResourceHandler.RESOURCE_IDENTIFIER)) { // Skip JSF resources (CSS/JS/Images/etc) 
        httpRes.setHeader("Cache-Control", "no-cache, no-store, must-revalidate"); // HTTP 1.1. 
        httpRes.setHeader("Pragma", "no-cache"); // HTTP 1.0. 
        httpRes.setDateHeader("Expires", 0); // Proxies. 
    }
    chain.doFilter(request, response);
}

But I have one problem, as explained here: How to move user to timeout page when session expires, if user click on browser back button the browser should instead send a fullworthy fresh HTTP request to the server.

But in my case it didn't. I see instead the ubiquituous Webpage has expired page which is in my opinion not a user friendly experience. What I want is NOT for it to load from browser cache but instead create a fresh request to the server and display the right page (Not the Webpage has Expired Page). Is it possible.

Please help. Thanks a lot.

Community
  • 1
  • 1
frazkok
  • 49
  • 1
  • 2
  • 11

1 Answers1

0

This can happen if the navigation has taken place by a POST request instead of a GET request.

You should make sure that page-to-page navigation always take place by a GET request. E.g.

<p:dataTable value="#{bean.items}" var="item">
    <p:column>
        <h:link value="detail" outcome="detail">
            <f:param name="id" value="#{item.id}" />
        </h:link>
    </p:column>
</p:dataTable>
BalusC
  • 1,082,665
  • 372
  • 3,610
  • 3,555
  • Hi BalusC, thanks for your answer. Im actually using h:link for the link to the second page. But it's still the same issue. – frazkok Jul 19 '12 at 00:51
  • The "webpage has expired" indicates that the non-cached page was opened by a POST request. – BalusC Jul 19 '12 at 01:39
  • Hi BalusC it worked in Opera but not in IE. Im using MSIE 9. Any idea? IE kept showing the dreaded Webpage has expired page. – frazkok Jul 19 '12 at 02:18
  • 1
    @frazkok how is the first page(listing) brought via a POST? From first page you go to second page(GET as described above), when you hit back you are going to first page again if first page was shown via POST request it will not work. – baba.kabira Jul 19 '12 at 05:39
  • first page was brought via primefaces . It's a POST is it? How to make it GET? – frazkok Jul 19 '12 at 06:03
  • Yes I tried already and it worked. Thanks BalusC and gbagga. I didn't see about the originating page was invoked via POST. – frazkok Jul 19 '12 at 07:27
  • For the benefit of other beginners: . – frazkok Jul 19 '12 at 08:05