3

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
    }
}
BalusC
  • 1,082,665
  • 372
  • 3,610
  • 3,555
techJava
  • 151
  • 8
  • Hi, please read [ask] and the [mcve] part in it (also see https://www.stackoverflow.com/tags/jsf/info) – Kukeltje Apr 29 '19 at 14:35

0 Answers0