In this tutorial, we will show you how to create a JSF 2 + PrimeFaces wed project, the final output is display a hello world string in PrimeFaces editor component.
  1. JSF 2.1.11
  2. Primefaces 3.3
  3. Eclipse 4.2
  4. Maven 3
  5. Tested on Tomcat 7
Note
PrimeFaces only requires a JAVA 5+ runtime and a JSF 2.x implementation as mandatory dependencies.

1. Project Directory

Prime Repo http://repository.primefaces.org org.primefaces primefaces 3.3
File : pom.xml Add JSF 2 and Primefaces dependencies.
xmlns="http://maven.apache.org/POM/4.0.0"  xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0  http://maven.apache.org/maven-v4_0_0.xsd"> 4.0.0
com.mkyong.core primefaces war 1.0-SNAPSHOT primefaces Maven Webapp http://maven.apache.org prime-repo Prime Repo http://repository.primefaces.org org.primefaces primefaces 3.3 com.sun.faces jsf-api 2.1.11 com.sun.faces jsf-impl 2.1.11 javax.servlet jstl 1.2 javax.servlet servlet-api 2.5 javax.servlet.jsp jsp-api 2.1 org.glassfish.web el-impl 2.2 org.apache.maven.plugins maven-compiler-plugin 2.3.2 1.6 1.6

3. Editor Bean

Create a simple bean, to provide data for PrimeFaces editor component later.
package com.mkyong.editor; import javax.faces.bean.ManagedBean; @ManagedBean(name = "editor")public class EditorBean {  private String value = "This editor is provided by PrimeFaces";  public String getValue() {  return value; }  public void setValue(String value) {  this.value = value; }}

4. Web Page

To use PrimeFaces components, just declares this namespace xmlns:p="http://primefaces.org/ui", and start use it, simple.
version="1.0" encoding="UTF-8"?>
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"><html xmlns="http://www.w3.org/1999/xhtml" xmlns:h="http://java.sun.com/jsf/html" xmlns:f="http://java.sun.com/jsf/core" xmlns:ui="http://java.sun.com/jsf/facelets" xmlns:p="http://primefaces.org/ui"> </h:head> <h1>Hello World PrimeFaces</h1> value="#{editor.value}" /> </h:form> </h:body></html>

5. Configuration

Note
PrimeFaces does not require any mandatory configuration
See web.xml below, only for JSF configuration.
 version="1.0" encoding="UTF-8"?>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">   PrimeFaces Web Application
javax.faces.PROJECT_S photoshop tutorial jar E Development faces/index.xhtml Faces Servlet javax.faces.webapp.FacesServlet 1 Faces Servlet /faces/* Faces Servlet *.jsf Faces Servlet *.faces Faces Servlet *.xhtml

6. Demo

See final output. http://localhost:8080/primefaces/

Download Source Code

Axact

Hamza Shafiq

Hello Friendz...My Name is Hamza Shafiq.I read in 1st year (CIT)Computer Information Technology in Sitara Insitute of Management Technology

Leave A Comment:

0 comments:

Back To Top