JSF 2 Installation & Configuration Using Eclipse

JavaServer Faces (JSF) is a server side component framework for building Java Technology web-based application. JavaServer Faces (JSF) consists of two main parts:

  • The JavaServer Faces API for representing components, managing their states, handling events, handling server side validations, and achieving data conversion; defining pages navigation, supporting internationalization and accessibility and providing extensibility for all these features.
  • Tag libraries for adding components to the web pages and connecting those components into their corresponding server side objects.

This post should clarify how a JSF framework could be installed and configured by using Eclipse IDE support.

Also Read:

Tools Used

This post will use the following tools for achieving the required installation and configuration:

Create JavaServer Faces Project

Eclipse IDE doesn’t provide a specific project for creating a JavaServer Faces (JSF), so we need to create a general dynamic project and adding a JavaServer Faces (JSF) facet into it. The facets define a characteristics and requirements for Java EE projects and are used as a part of the runtime configuration, so adding a JSF facet into created project will help us installing the required JSF libraries and allow us to adhere the required view for dealing with the different parts of JSF application development.

The steps required for creating and configuring a JavaServer Faces project using Eclipse IDE are as follow:

  1. Create a new dynamic project.
  2. Right-Click on the created project -> select properties.
  3. While in a properties window, select project facets.
  4. Make sure that the version of your Dynamic Web Module is at least 2.5.
  5. Tick at the Java and select the version of 1.6 (it depends on your JDK that you are using)
  6. Tick at the JavaServer Faces and select the version of 2.2

By end of the previous steps, you should be informed about further configuration is required. Hover over the link and click it.

JSF Facet in Eclipse

Create JavaServer Faces Library

By clicking on the Further configuration required link, it’s the time for creating the JavaServer Faces library. To create library you have to follow the below steps:

  1. While a window of JSF Capabilities is opened, click on the download library.
  2. The JavaServer Faces library is being searched and you should at least see a JSF 2.2 (Mojarra 2.2.0) library. Mojarra is one of the implementations exist for JavaServer Faces (JSF 2).
  3. Tick the JSF 2.2 (Mojarra 2.2.0) library.
  4. Specify the library name that you would use it as a reference name for the installed JavaServer Faces library.
  5. Specify the Download destination that you would use a location for saving the binaries of the installed JavaServer Faces library.

You should get the same dialog as shown below

JSF Library Installed

  1. Click the next button for complete the installation.
  2. Tick the i accept the terms of this license.
  3. The JavaServer Faces library is being installed.
  4. Once the installation has been finished, you should see the JSF 2.2 (Mojarra 2.2.0) library is listed as a choice in the JSF Implementation Library.
  5. Tick the JSF 2.2 (Mojarra 2.2.0) listed library.
  6. Click Okay to close the dialog.
  7. Click Okay  to close the project facets dialog.

By ending the above steps, you are ready for using JavaServer Faces in your project.

Configure Apache Tomcat

If you’ve ever been configured the Apache Tomcat for executing a JSF samples, you’ve requested to install and configure it for next coming use. Follow the below steps for making Apache Tomcat for use.

  • From the dynamic project and underneath of Target Runtime -> Select New Runtime

Eclipse Tomcat Configurations

  1. Select Apache Tomcat v7.0 -> Click Next
  2. Type the name of the server that you’ve been installing.
  3. Navigate into the destination path of the Apache Tomcat 7.0 (Download the Apache Tomcat 7.0).
  4. Click on the server pane by Window -> show view -> Servers or Other -> Servers.
  5. You should find the following message (No Servers are available. Click this link to create a new server …)
  6. Choose Tomcat 7.0
  7. Let’s the remaining configuration without touch.
  8. Click next and finish.

Adding of Apache Server

  • The server is installed and is ready for use

Create JavaServer Faces Page

After creating, configuring and installing the all libraries that required to start using of JavaServer Faces, it’s time to create the first Hello World sample.

  • Right-Click the project’s WebContent.
  • Select New -> HTML File.
  • Name your file with an index.xhtml -> Click Next
  • Select New XHTML File (1.0 strict) -> Click Finish

The page that you will create it must be as below

<?xml version="1.0" encoding="ISO-8859-1" ?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">

<html xmlns="http://www.w3.org/1999/xhtml"
 <h:outputText value="Hello World !"></h:outputText>

Run index.xhtml

To run the index.xhtml you should follow the below steps:

  • Righ-Click on the index.xhtml
  • Select Run As
  • Select the configured Apache Server that you’ve done before.
  • Click finish.
  • You should see the message Hello World !

Leave a Reply

Your email address will not be published. Required fields are marked *

Pin It on Pinterest

Share This

Share this post with your friends!