1

How can I invoke a method on a managed bean when pressing backbutton or F5?

BalusC
  • 1,082,665
  • 372
  • 3,610
  • 3,555
akub
  • 99
  • 2
  • 10

1 Answers1

1

If the bean is request scoped and the page is served with response headers which instructs the browser to not cache the page, then you can do that job in the bean's constructor or @PostConstruct method.

E.g.

public class Bean {

    public Bean() {
        // Here, in the constructor.
    }

    @PostConstruct
    public void init() {
        // Or here, in the postconstructor.
    }

}

The @PostConstruct method is particularly useful if you're injecting dependencies by @ManagedProperty, @EJB or @Inject, etc and want to do the initialization job based on those dependencies.

Community
  • 1
  • 1
BalusC
  • 1,082,665
  • 372
  • 3,610
  • 3,555
  • sorry but i didnt understand your answer, can u be more specific – akub Sep 03 '11 at 15:43
  • Put the code in constructor of the bean, or a method which has the `@PostConstruct` annotation. Further you need to make sure that JSF requests are not cached by the browser. You can do that with a `Filter`. – BalusC Oct 25 '11 at 13:36