dev@javaserverfaces.java.net

Re: Can't find FacesContext

From: Ryan Lubke <Ryan.Lubke_at_Sun.COM>
Date: Thu, 23 Oct 2008 16:23:21 -0700

Ralph Bunker wrote:
> If this is not the right place to post this, please let me know a
> better place.
>
> I am preparing to teach JSF and want to be able to tell my students
> that FacesServlet is "just" a Servlet. To convince myself of that, I
> created a new Web Application project in NetBeans 6.1 and did not add
> the JSF libraries to it. I then downloaded the 1.2_09 Mojarra build
> from https://javaserverfaces.dev.java.net/download.html and copied all
> packages and config files to my NetBeans project. I created a small
> page with just a <f:view/> tag and ran that page.
>
> I got it to compile and ConfigListener.contextInitialized and
> FacesServlet.init appear to run correctly on thread
> Thread[httpWorkerThread-4848-0,10,Grizzly]. In particular,
> FacesContext.setInstance() is called before any call
> FacesContext.getInstance() so that getInstance never returns null.
The FacesContext ThreadLocal will be populated by the FacesServlet when
the request is processed by the FacesServlet.

If the ViewTag is stating that no FacesContext can be found, this
indicats your request isn't going through the FacesServlet.

Example:

FacesServlet is mapped to /faces/*

Request: http://localhost:8080/testapp/test.jsp -> Fails with
FacesContext not found
Request: http://localhost:8080/testapp/faces/test.jsp -> works as the
request includes the FacesServlet in the path

FacesServlet is mapped to *.jsf

Request: http://localhost:8080/testapp/test.jsp -> Fails with
FacesContext not found
Request: http://localhost:8080/testapp/test.jsf -> works as the request
invokes the extension mapping for the FacesServlet


>
> However, when com.sun.faces.taglib.jsf_core.ViewTag.setJspId is called
> (it is running on thread
> Thread[httpSSLWorkerThread-8080-1,10,Grizzly]), it calls
> getFacesContext which calls FacesServlet.getInstance() *before any
> call to FacesServlet.setInstance() on that thread *and an
> "java.lang.RuntimeException: Cannot find FacesContext" exception is
> thrown because getInstance returns null.
>
> My question is who is supposed to call FacesServlet.setInstance() on
> the ViewTag thread?
>
> Any suggestions will be really appreciated.
>
> thanks,
> --ralph---------------------------------------------------------------------
> To unsubscribe, e-mail: dev-unsubscribe_at_javaserverfaces.dev.java.net
> For additional commands, e-mail: dev-help_at_javaserverfaces.dev.java.net