Sanat Pandey
Sanat Pandey

Reputation: 4103

How to use PrimeFaces 3.2 in Eclipse Indigo SR2?

I'm trying to use PrimeFaces 3.2. I'm using Eclipse Indigo SR2. I'm creating a JSP page using PrimeFaces tags. The standard <h:commandButton> is working, but <p:commandButton> is not working.

<%@ page language="java" contentType="text/html; charset=ISO-8859-1" pageEncoding="ISO-8859-1"%>
<%@ taglib prefix="f"  uri="http://java.sun.com/jsf/core"%>
<%@ taglib prefix="h"  uri="http://java.sun.com/jsf/html"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html  xmlns:p="http://primefaces.org/ui">
<head>

</head>
<body>
<f:view>
        <h:form>
        <h:commandButton value="Click"></h:commandButton>
        <p:commandButton value="shfgldjfkl"></p:commandButton>
        </h:form>
</f:view>
</body>
</html>

My output is this:

enter image description here

When I'm taking a JSF XHTML page in Indigo Service Release 2, then my code is not running my page is blank.

How can I use PrimeFaces 3.2?

Upvotes: 0

Views: 3023

Answers (2)

Heidi Lilybeth
Heidi Lilybeth

Reputation: 127

Well I think you should use JSF or facelet personally I never try implementing JSP with primeface, by the way why implement JSP if you can achieve the same result in JSF or facelet so I recommend to move on to JSF 2.0

Upvotes: 0

BalusC
BalusC

Reputation: 1108722

JSP is deprecated since JSF 2.0 and succeeded by Facelets. All JSF 2.0 compatible component libraries like PrimeFaces >2.x do not have taglibs for JSP anymore, but only for Facelets.

The <html xmlns:p="http://primefaces.org/ui"> which you placed in the JSP file won't be recognized by JSP at all. JSF taglibs on XML namespaces work in Facelets only.

Forget JSP. Concentrate on Facelets.

Back to your Facelets problem of a blank page, make sure that you've a <h:head> instead of <head> (otherwise JSF/PrimeFaces won't be able to auto-include the necessary CSS/JS files) and that your request URL matches the URL pattern of the FacesServlet as definied in web.xml (otherwise FacesServlet won't be invoked at all and hence not be able to convert JSF to HTML; you'd have confirmed this by rightclick, View Source in webbrowser).

Here's the complete Facelets snippet /demo.xhtml:

<!DOCTYPE html>
<html lang="en"
    xmlns="http://www.w3.org/1999/xhtml"
    xmlns:f="http://java.sun.com/jsf/core"
    xmlns:h="http://java.sun.com/jsf/html"
    xmlns:ui="http://java.sun.com/jsf/facelets"
    xmlns:p="http://primefaces.org/ui">
    <h:head>
        <title>PrimeFaces demo</title>
    </h:head>
    <h:body>
        <h:form>
            <p:commandButton value="submit" />
        </h:form>
    </h:body>
</html>

If the FacesServlet is in web.xml mapped on an URL pattern of *.xhtml as follows:

<servlet>
    <servlet-name>facesServlet</servlet-name>
    <servlet-class>javax.faces.webapp.FacesServlet</servlet-class>
    <load-on-startup>1</load-on-startup>
</servlet>
<servlet-mapping>
    <servlet-name>facesServlet</servlet-name>
    <url-pattern>*.xhtml</url-pattern>
</servlet-mapping>

then you can just open it by the very same filename in the URL without fiddling with virtual URLs like *.jsf, /faces/*, etc:

http://localhost:8080/contextname/demo.xhtml

Upvotes: 2

Related Questions