0

How to create a simple JSF2 and Primefaces Application in Eclipse

Background

This article demonstrates how to create a simple JSF that uses Primefaces in Eclipse.

Software Environment

  • Windows 7 Professional SP1
  • Eclipse – Kepler Release
  • Java 1.7 (1.7.0_67 – Windows x86)
  • JSF 2.2
    • Downloaded, and referenced as part of a Dynamic Web Project in Eclipse
  • Primefaces 4.0
    • Downloaded fromĀ www.primefaces.org
    • Place it in the project in WebContent\WEB-INF\lib and reference it

Create a Dynamic Web Project

1. Choose File -> Other… -> Dynamic Web Project (Under Web folder)

jsf2-primefaces4-001

2. Specify Project Details

For this article, we set Target runtime to Apache Tomcat v7.0, module version to 3.0, and Configuration to “JavaServer Faces v2.2 Project”. Then, click Next.

jsf2-primefaces4-002

Just click next on the second screen.

jsf2-primefaces4-003

Leave things as they are and just simply click Next again.

jsf2-primefaces4-004

When you reach this point, your eclipse may or may not list anything in JSF Implementation Library right after choosing the Type (e.g., User Library). Click the download button (bluish icon of a diskette with an arrow pointing downward) just located to the right of the list control.

jsf2-primefaces4-005

Downloading the JSF Library

jsf2-primefaces4-006

Accept the license agreement, and click Finish.

jsf2-primefaces4-007

Click Finish.

jsf2-primefaces4-008

jsf2-primefaces4-009

Download PrimeFaces 4.0

jsf2-primefaces4-010

Once primefaces-4.0.jar has been downloaded successfully, put the file in WebContent\WEB-INF\lib in the Eclipse project.

Java Classes

We need two classes – Java Bean and JSF-managed bean classes.

The Java Bean

JSF-Managed Bean

The View

Sample Output

jsf2-primefaces4-013

Download the Project

https://www.dropbox.com/s/42mbsyqjmzse77s/JSFPrimeFacesApp.zip?dl=0