0

I have some bean using the @WebServlet annotation:

@WebServlet("tools/httpProjectLoader.xhtml")
public class HttpProjectLoader extends HttpServlet {
    @Override
    protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        ...
    }
}

I want to use that URL to react on links from emails, for example:

http://myhost/webapp/tools/httpProjectLoader.xhtml?pn=1000000654

The web.xml uses the following setup for the FacesServlet:

<servlet>
    <servlet-name>Faces Servlet</servlet-name>
    <servlet-class>javax.faces.webapp.FacesServlet</servlet-class>
    <load-on-startup>1</load-on-startup>
</servlet>
<servlet-mapping>
    <servlet-name>Faces Servlet</servlet-name>
    <url-pattern>*.xhtml</url-pattern>
</servlet-mapping>

When I try to access FacesContext.getCurrentInstance() from within #doGet(...) the returned value is always null. Why? And how can I handle this? I want to use some UI (CDI) beans to init the application and forward to a resulting page. Whenever some code uses i.e. FacesContext.getCurrentInstance().addMessage(...) it fails with a NullPointerException.

BalusC
  • 1,082,665
  • 372
  • 3,610
  • 3,555
Daniel Bleisteiner
  • 3,190
  • 1
  • 33
  • 47
  • 1
    This is a huge [XY-problem](http://meta.stackexchange.com/questions/66377/what-is-the-xy-problem). You basically need to ask this question: http://stackoverflow.com/q/10724428 Is this acceptable as dupe? The answer to the technical problem with the `FacesContext` is answered here: http://stackoverflow.com/q/14045242 – BalusC Sep 07 '15 at 17:34
  • @BalusC Thanks! These view parameters should help me out. I'll change my implementation to use a JSP instead. – Daniel Bleisteiner Sep 07 '15 at 17:41
  • ...to be more precise: xhtml page using JSF tags. – Daniel Bleisteiner Sep 07 '15 at 18:05
  • You cannot combine JSF with servlet, neither JSP, `FacesContext.getCurrentInstance()` are accessible in jsf beans. your servlet doesn't make any sense too. –  Sep 08 '15 at 01:00

0 Answers0