Java Server Faces in Action – JSF Example

A quick recap:

In the previous tutorial, we have seen Facelets introduction with its advantages and importance. We have learned that Facelets provide reusable templates designing capabilities. In this tutorial, we will try to understand the JSF example in detail.

Getting Started with JSF:

We have already seen the JSF Getting Started part of this tutorial. Now we will see how to successfully create n application using JSF. We will use the same environment for this tutorial as we have set earlier in the Servlet series. This tutorial will help you to set the environment if you have not seen yet.

  1. Set up environment
  2. Create a dynamic web application

Requirements for JSF Development

  • You should have JDK installed.
  • You should have Environment variable properly set.
  • JEE Eclipse properly configured with JRE.
  • Apache Tomcat configured with JEE Eclipse.
  • JSF Library downloaded and configured with JEE Eclipse.

Before Start Creating Application:

We are assuming following things about you before starting this tutorial.

  • You know how to install JDK
  • You know how to set up environment variables
  • You know how to configure Tomcat with Eclipse for Project Deployments.
  • You know how to create Dynamic Web Application project in JEE Eclipse

If you have doubts on any of the points above you can consult to following tutorials for more clarification. Set up the environment , Create a dynamic web application and JSF Getting Started part of this JSF introduction tutorial.

Start Creating Application:

First, create a Managed Bean Class named “” with the following source

Then create a View File with .xhtml extension. The procedure of creation will be the same as we have created HTML file in servlets. The difference here will be only that; we will name the file with .xhtml extension.

Finally, edit the project web.xml file as follows.

In the above source, the welcome-file-list tag is indicating the first file to be loaded when we run the project.

Now the JSF example is ready to run. You can Run It by Right Clicking on the Project –> Selecting Run As –> Run On Server.

The output of this JSF example will look like this.

JSF example Output
JSF example Output

JSF Form View

In JSF we can make forms using like this.

This code will create a JSF form for you. You can handle form submissions with a managed beans

The output will look like this.

JSF user input form
JSF user input form



In this tutorial, we have accomplished following things.

  • Getting started with JSF implementation
  • Major Requirements for JSF development
  • Things to remember during development
  • Java Server Faces Example

Hope that you like this tutorial. Stay tuned for more upcoming tutorials. Stay Blessed!

About Author: Uzair Ahmed Khan is Technical Content Writer, Computer Software Blogger and Software Engineer Enthusiast with a keen eye on Java Technologies other Related Developments.

Leave a Reply

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