As I was told and found on websites, my bean will only be executed if I have a call for it on my .xhtml.
Is it possible to call my bean without any EL expression?
I need this because my HomeController is calling a method that checks for the session status and on my home.xhtml and don’t have any need for fall this bean, for now.
You need to look for a solution in a different direction.
If you’re homegrowing user authentication instead of using container managed authentication, then you normally use a servlet filter for the particular purpose of checking if an user is logged in or not.
The servlet filter can like as servlets (like
FacesServlet) be mapped on a particular URL pattern. It will then be invoked on every request matching that URL pattern. You can explore request/session data in the filter and then handle the request/response accordingly by either continuning the filter chain, or by sending a redirect.You need to implement
javax.servlet.Filterinterface accordingly. Here’s a kickoff example of how thedoFilter()method should be implemented assuming that you’ve a@SessionScopedmanaged beanLoginController. JSF stores session scoped managed beans as attributes ofHttpSession.Map this filter on an URL pattern covering the restricted pages, e.g.
/app/*.Update if the
login.xhtmlis also covered by this URL pattern and you really can’t change it, then change theifblock as follows: