Search code examples
jsf-2tomcat7

Faces Servlet not parsing .xhtml pages in jsf 2. running on tomcat 7


I am trying to create a JSF 2.0 application in eclipse with tomcat7. The project is running successfully but the jsf html and core components are not rendered in browser. I think Faces Servlet I have configured in web.xml.

Following is the web.xml file -

<welcome-file-list>
<welcome-file>faces/index.xhtml</welcome-file>    
</welcome-file-list>

<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>  

<context-param>
    <description>State saving method: 'client' or 'server' (=default)</description>
    <param-name>javax.faces.STATE_SAVING_METHOD</param-name>
    <param-value>client</param-value>
</context-param>
<context-param>
    <param-name>javax.servlet.jsp.jstl.fmt.localizationContext</param-name>
    <param-value>resources.application</param-value>
 </context-param>
 <listener>
    <listener-class>com.sun.faces.config.ConfigureListener</listener-class>
 </listener>

I have my index.xhtml page outside WEB-INF. Its shown in browser but the jsf components are not see in browser. Can anyone please tell what is going wrong.

I have included following jars in WEB-INF/lib - 1. commons-annotations.jar 2. commons-beansutil.jar 3. commons-collection.jar 4. commons-digester.jar 5. commons-logging.jar 6. jsf-api.jar (from mojra 2.0) 7. jsf-impl.jar (from mojra 2.0) 8. jstl.jar 9. standard.jar

Thanks


Solution

  • Try these .. These were specified to me for my own question once..

    1. You don't need and even should not include the JSF jars. Those are already part of Java EE.
    2. Secondly, you definitely don't need and absolutely should not use the separate Facelets jar in combination with JSF 2.x. Facelets is already part of JSF 2.x.
    3. You also should not include the JSTL jar. That one too is provided by Java EE. If u have commons jars by Apache commons, then those are fine but they are NOT needed for JSF. Include them only if you want to use them directly in your application code.
    4. Try to get latest JSF (mojara 2.x).

    Also you can modify your web.xml like this and try:

     <welcome-file-list>
     <welcome-file>index.xhtml</welcome-file>    
     </welcome-file-list> 
    
    
     <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 tried, I removed adding jsf jars separately. And it worked, displaying all the jsf tags. Also make sure you have all the required taglibs in your xhtml page, namely :

    <html xmlns="http://www.w3.org/1999/xhtml"
    xmlns:h="http://java.sun.com/jsf/html"
    xmlns:ui="http://java.sun.com/jsf/facelets"
    xmlns:p="http://primefaces.org/ui"
    xmlns:f="http://java.sun.com/jsf/core">
    

    See if this works.