1

I'm working with a web application with jsf, and I'm quite new to this.
There's a form that the user fills and send. The server receives the form in a backing bean, it does the actions needed and redirects to a different page.
The problem is that when the user hits the back button of the browser, it gets back to the form with all the fields filled with the data introduced by the user. I need to clean that form.
I've tried making manual clean-up of the fields when the page loads, and it doesn't work, the form is refilled with the previous data.
Any help with this problem?

Thanks in advance.

1 Answer 1

1

Two possible issues:

  1. your browser fills in the values out of courtesy, disable that using cache control or using omnifaces' CacheControlFilter, which you just can enable via web.xml. Also see how to do autocomplete="off" at form level in JSF to prevent the browser's autocomplete function from filling in previous values.

  2. Your server-side code saving those values is still alive. You don't mention which scope you use, but remember that @ViewScoped beans and basically everything stored in the session is not necessarily destroyed on navigation. If you can't manage your bean's lifecycle so that they are destroyed automatically, you need to reset the form values yourself before redirection:

    @ManagedBean @SessionScoped 
    public class TestBean implements Serializable {
        private String myString;
    
        public String saveIt() {
            doStuffWithString();
            myString = "";
            return "saved";
        }
    }
    
3
  • Thanks for your answer. 2. Yes, it's session scoped, but the object are put to null in the java code, so that's not the problem. I've chekced the session debugging the code, and after doing the action, the object is null, but when going back in the browser, it fills again. So I'm going now to try to check the cache control. I'm also trying to make a reset(form) but I have problems to control it to be executed only once. I've also tried the autocomplete=off, but that's not the solution for my problem. Thanks again Feb 19, 2014 at 14:33
  • I tried the disabling the cache and it work, so that's a good way to solve my problem, though finally the costumer when told about this problem finally accepted a different solution, that is not letting the user go back to the form page (making a window.history.forward(1)) . It's not exactly what it was requested but it fills the costumer necessity. Thanks again. Feb 25, 2014 at 10:55
  • @user3207908 Glad you found a solution!
    – mabi
    Feb 25, 2014 at 10:59

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.