Search code examples
javajsfphaselistener

How to register a JSF 1.2 PhaseListener in a Servlet.init()?


Is it possible? FacesContext.getCurrentInstance() returns null.


Solution

  • A regular servlet isn't initialized/called during a JSF request, so there's no means of a FacesContext in a servlet. Only when the request URL matches the FacesServlet, then there's a FacesContext. You should register the PhaseListener in faces-config.xml or in a JSF managed bean instead. Consider doing it in the (post)constructor of an application scoped managed bean.