4

I am trying to build simple JSF application using primefaces but somehow primefaces components are not getting rendered properly. I dont understand what is going wrong.

I am trying to display following Facelet file :

<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:f="http://java.sun.com/jsf/core"
    xmlns:p="http://primefaces.prime.com.tr/ui">
    <h:head>
        <link type="text/css" 
                rel="stylesheet"
                href="/Themes/primefaces-dot-luv/theme.css" />
    </h:head>
    <h:body>
        <p:spinner value="100" style="height: 10px" />
        <br/>
        <p:button value="Navigate"></p:button>
    </h:body>
</html>

I am using eclipse to run the app on tomcat server. When I run the application and view the page source in browser(firefox) I get following source :

<html xmlns="http://www.w3.org/1999/xhtml" xmlns:p="http://primefaces.prime.com.tr/ui">
    <head>
        <link type="text/css" rel="stylesheet" href="Themes/primefaces-dot-luv/theme.css" />
    </head>
    <body>
        <p:spinner value="100" style="height: 10px"></p:spinner>
        <br />
        <p:button value="Navigate"></p:button>
    </body>
</html>

I think PrimeFaces components are not getting rendered properly. Other JSF tags like <h:head> and <h:body> are converted correctly to <head> and <body> elements respectively. Only tags starting with <p:> are not converted.

Following is my project structure :

enter image description here

My web.xml looks like this:

<?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>HelloJSF</display-name>
  <welcome-file-list>
    <welcome-file>index.jsp</welcome-file>
    <welcome-file>default.jsp</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>
    <param-name>primefaces.THEME</param-name>
    <param-value>none</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>
    <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>
  <servlet-mapping>
    <servlet-name>Faces Servlet</servlet-name>
    <url-pattern>*.jsf</url-pattern>
  </servlet-mapping>
  <servlet-mapping>
    <servlet-name>Faces Servlet</servlet-name>
    <url-pattern>*.faces</url-pattern>
  </servlet-mapping>
</web-app>

I am using eclipse , tomcat server. JSF 2 and primefaces 3 library.

Hi, After some close inspection of entire project I found out that primefaces jar dowlonaded from site did not had any classes. Jar itself was corrupt. I downloaded same jar thrice then also jar was getting corrupt. So I downloaded zip file containing source and binaries and my application started working.

Shekhar
  • 11,438
  • 36
  • 130
  • 186

3 Answers3

5

Try changing your web.xml servlet mapping:

<servlet-mapping>
  <servlet-name>Faces Servlet</servlet-name>
  <url-pattern>*.xhtml</url-pattern>
 </servlet-mapping>

The way to tell if the Facelets Servlet is processing your xhtml is to look at what the browser receives. If it looks like your xhtml file then you have something mis-configured.

AlanObject
  • 9,613
  • 19
  • 86
  • 142
  • The JSF core, HTML and Facelets taglibs are however properly parsed, so `FacesServlet` is definitely been invoked. – BalusC Aug 28 '11 at 18:55
0

Your need change

xmlns:p="http://primefaces.prime.com.tr/ui"

to

xmlns:p="http://primefaces.org/ui"
j0k
  • 22,600
  • 28
  • 79
  • 90
ratking
  • 11
  • 1
    This was introduced since 3.0 M4, but OP is using 3.0 M2. So this answer is wrong. Note that the currently accepted answer of AlanObject is also wrong; the OP already solved the problem by itself (see the quote at the bottom of the question), but the OP never posted it as an answer for some reason (which is indeed confusing and not the right way to use Stack Overflow). – BalusC Aug 06 '12 at 12:24
0

You should change your namespace into xmlns:p="http://primefaces.org/ui"

and implement button like this way

 <p:commandButton value="Home" process="@this" action="actionMethod()" immediate="true" rendered="true or renderingMethod()" />
Baby Groot
  • 4,637
  • 39
  • 52
  • 71