How can I invoke a method on a managed bean when pressing backbutton or F5?
Asked
Active
Viewed 641 times
1 Answers
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.
-
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