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.
Tools used :
- JSF 2.1.11
- Primefaces 3.3
- Eclipse 4.2
- Maven 3
- Tested on Tomcat 7
Note
PrimeFaces only requires a JAVA 5+ runtime and a JSF 2.x implementation as mandatory dependencies.
PrimeFaces only requires a JAVA 5+ runtime and a JSF 2.x implementation as mandatory dependencies.
1. Project Directory
Final project directory.
2. Project Dependency
To use PrimeFaces, you only need single
primefaces-{version}.jar
, but this jar is not available on Maven central repository, So, you need to declare PrimeFaces own repository :
Refer here : PrimeFaces download reference
prime-repo
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
3. Editor Bean
Create a simple bean, to provide data for PrimeFaces editor component later.
File : EditorBean.java
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.
File : index.xhtml
version="1.0" encoding="UTF-8"?>
5. Configuration
Note
PrimeFaces does not require any mandatory configuration
PrimeFaces does not require any mandatory configuration
See
web.xml
below, only for JSF configuration.
File : web.xml
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
6. Demo
See final output. http://localhost:8080/primefaces/