Search code examples
eclipsejsf-2primefacesfacelets

Primefaces tags not being recognized in Eclipse Facelets project


I'm trying to make a simple PrimeFaces example like the tutorial on their website. I'm basically having the exact same problem as this user but I don't have an empty jar file like he did. The h: tags are rendering fine, but the p: tags show up in the HTML as p: tags. Same problem with PrimeFaces 3.1.1 and 3.2. Here is my web.xml file.

<?xml version="1.0" encoding="UTF-8"?>
<web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://java.sun.com/xml/ns/javaee" xmlns:web="http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd" xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd" id="WebApp_ID" version="2.5">
  <display-name>jsf</display-name>
  <welcome-file-list>
    <welcome-file>Login.xhtml</welcome-file>
  </welcome-file-list>
  <context-param>
    <param-name>javax.servlet.jsp.jstl.fmt.localizationContext</param-name>
    <param-value>resources.application</param-value>
 </context-param>
  <context-param>
    <description>State saving method: 'client' or 'server' (=default). See JSF    Specification 2.5.2</description>
    <param-name>javax.faces.STATE_SAVING_METHOD</param-name>
    <param-value>client</param-value>
  </context-param>
  <context-param>
    <description></description>
<param-name>org.apache.myfaces.ALLOW_JAVASCRIPT</param-name>
<param-value>true</param-value>
  </context-param>
<context-param>
<description></description>
<param-name>org.apache.myfaces.PRETTY_HTML</param-name>
<param-value>true</param-value>
</context-param>
  <context-param>
<param-name>org.apache.myfaces.DETECT_JAVASCRIPT</param-name>
<param-value>false</param-value>
</context-param>
<context-param>
  <description></description>
    <param-name>org.apache.myfaces.AUTO_SCROLL</param-name>
<param-value>true</param-value>
</context-param>
<listener>
  <listener-class>org.apache.myfaces.webapp.StartupServletContextListener</listener-  class>
</listener>
<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>
</web-app>

My XHTML file looks like this.

<html xmlns="http://www.w3.org/1999/xhtml"
  xmlns:ui="http://java.sun.com/jsf/facelets"
  xmlns:h="http://java.sun.com/jsf/html" 
  xmlns:p="http://primefaces.org/ui">
<h:head>
  <title><ui:insert name="title">Facelets Tutorial</ui:insert></title>
</h:head>
<body>
    <p:editor />
    <p:spinner />
</body>
</html>

I start up my server (Tomcat 6) and the rendered HTML looks like this, h: tags rendered fine and p: tags still p: tags.

<html xmlns="http://www.w3.org/1999/xhtml" xmlns:p="http://primefaces.org/ui"><head>
  <title>Facelets Tutorial</title></head>
<body>
    <p:editor></p:editor>
    <p:spinner></p:spinner>
</body>
</html>

I added the PrimeFaces jar to my build path and I know it's being recognized because I can import/use PrimeFaces classes just fine in my source files. I even downloaded the PF source and added it to my project to make sure it could be seen, and I still have this problem. Do I need some additional configuration in my web.xml?


Solution

  • Build path or not, you need to make sure that the PrimeFaces JAR file ultimately ends up in /WEB-INF/lib folder of the built and deployed WAR file. The symptoms indicate that this is not the case.

    In Eclipse, that would be just a matter of dropping the PrimeFaces JAR file straight in the /WEB-INF/lib folder of the web project structure. Nothing else needs to be done; Eclipse will automatically add it to the build path and deployment assembly. Don't forget to undo all changes you made in the build path before while attempting to install PrimeFaces.

    If you really insist to keep the JAR elsewhere and manually manage the build path for some reason, then you'd need to manually add it in the Deployment Assembly section of the project's properties as well to get it to ultimately end up in the /WEB-INF/lib folder of the WAR.