Reputation: 99
How can I invoke a method on a managed bean when pressing backbutton or F5?
Upvotes: 1
Views: 645
Reputation: 1108722
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.
Upvotes: 1