5

We use JSF2, we have a page with form fields with command button linked to backing bean.

When we access the form page, enter the values and submit, the backing bean recieves the correct values and takes it to the next page. If I press back button in the browser, it takes to previous page with form. If I enter new values in the form and submit, the backing bean still recieves the old values in Step 1.

BalusC
  • 1,082,665
  • 372
  • 3,610
  • 3,555
user684434
  • 1,165
  • 2
  • 19
  • 39

2 Answers2

6

This is odd. Perhaps your bean is put in the session scope and/or the browser has requested the page from the cache. To start, you'd like to disable browser cache for all dynamic pages by a filter which sets the proper response headers.

@Override
public void doFilter(ServletRequest request, ServletResponse response, FilterChain chain) throws IOException, ServletException {
    HttpServletRequest req = (HttpServletRequest) request;
    HttpServletResponse res = (HttpServletResponse) response;

    if (!req.getRequestURI().startsWith(req.getContextPath() + ResourceHandler.RESOURCE_IDENTIFIER)) { // Skip JSF resources (CSS/JS/Images/etc)
        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);
}

Map this filter on the servlet name of the FacesServlet or on the same URL pattern.

Last, but not least, do not put your form beans in the session scope. Put them in the request or view scope.

Community
  • 1
  • 1
BalusC
  • 1,082,665
  • 372
  • 3,610
  • 3,555
  • I found the same with GlassFish 3.1.1 today, with a ViewScope bean. When I go back and press the submit button the second time the button **action is not executed** and the browser (FireFox) displays the view with the previous result. The button code is ``. The search form and the result datatable are in the same view xhtml file (but included as facelets). I'll try to analyze it. – mjn Feb 01 '12 at 10:39
  • It works different in Internet Explorer - back to the search form clears all input values so I need to fill the form again and submit works as expected. – mjn Feb 01 '12 at 10:46
0

learn JSF carefully, JSF2.0 in the glassfish work nice, if you have viewscoped beans and press browser back/next links JSF carefully loaded the pervious page also you can see your data and submit it.

Armen
  • 21
  • 1