| Author |
Getting Cannot find FacesContext and sometime showing html codes in the page
|
Kaushik Baral
Greenhorn
Joined: Aug 08, 2009
Posts: 18
|
|
hi,
i was trying some jsf examples and i am getting this error "Cannot find FacesContext" and when im mapping my "faces-config.xml" and "web.xml" like this i can see the html and other code on the jsp page. i am using tomcat 5. web.xml and faces-config.xml is given below
web.xml
<context-param>
<param-name>javax.faces.CONFIG_FILES</param-name>
<param-value>/WEB-INF/faces-config.xml</param-value>
</context-param>
<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>/faces/*</url-pattern>
</servlet-mapping>
</web-app>
faces-config.xml
<faces-config>
<navigation-rule>
<from-view-id> /login.jsf</from-view-id>
<navigation-case>
<from-outcome>success</from-outcome>
<to-view-id>/home.jsf</to-view-id>
</navigation-case>
<navigation-case>
<from-outcome>failure</from-outcome>
<to-view-id>/login.jsf</to-view-id>
</navigation-case>
</navigation-rule>
<managed-bean>
<managed-bean-name>UserBean</managed-bean-name>
<managed-bean-class>com.tm.UserBean</managed-bean-class>
<managed-bean-scope>session</managed-bean-scope>
</managed-bean>
</faces-config>
i have changed my jsp files extension to jsf (home.jsf and login.jsf). is this required or extension home.jsp is fine?
thanks a lot in advance
|
 |
Rafael Fontoura
Greenhorn
Joined: Nov 06, 2007
Posts: 11
|
|
Well, don't know what's the real problem, but I saw few problems here:
1. Your JSF Servlet mapping points to /faces/*, but none of your page files matches this pattern.
2. Unless you're using JSF 1.x, the file type to use for pages is .xhtml. You write on XHTML files, but the browser/internal requests are for ".jsf files".
I recommend you read some tutorials like www.coreservlets.com/JSF-Tutorial/jsf2/ (if you're using JSF 2.0).
|
SCJP 5.0 | SCWCD 5
|
 |
Tim Holloway
Saloon Keeper
Joined: Jun 25, 2001
Posts: 14456
|
|
Rafael Fontoura wrote:Well, don't know what's the real problem, but I saw few problems here:
Those were, in fact the problems. The J2EE server will only route URLs that match the JSF servlet's (FacesServlet) request URL pattern(s). Any other URLs will be on their own.
It's unfortunate that JSF started out using the ".jsp" file extension, because unlike "real" JSPs, JSF JSP file are not compiled into servlets and executed. They must be read as templates by the FacesServlet so that the FacesServlet can operate as an MVC master controller. The FacesServlet constructs a FacesContext to help it do that, but it then destroys that FacesContext once the output has been sent back to the user. A new FacesContext is created for each request, and therefore the FacesContext won't exist (and therefore cannot be found) on URLs that weren't routed to the FacesServlet.
|
Customer surveys are for companies who didn't pay proper attention to begin with.
|
 |
 |
|
|
subject: Getting Cannot find FacesContext and sometime showing html codes in the page
|
|
|