I have a dashboard.xhtml
JSF page and the corresponding managed bean DashboardManager
. In JSF page, I'm checking if the user is logged in or not by calling a method from a managed bean isUserLoggedIn()
and in case of not logged in, redirecting the user to access-denied page, using <f:event> preRenderView
. But here problem is that managed bean is already instantiated and the EJBs in DashboardManager
are injected and the init() method marked with @PostConstruct
annotation is executed as well, calling several other methods hitting DB, which of course I don't want to, as user is not logged in yet. Is there any other efficient way where to redirect user, in case of not logged in, to another page without the init() method marked with @PostConstruct being called? Thanks.
@ManagedBean
public class DashboardManager {
@PostConstruct
public void init() {
findPendingCustomerOrders(); // hits DB and fetch data
findDeliverables();// fetch data
findProductBelowMinStock(); // fetch data
// some more methods fetching data from DB
}
}