Getting Started with Java Server Faces (JSF)

We have completed our Servlets and JSPs series, and now we will start a new series on Java Server Faces. It is a Standard Java framework for interface development, in this whole course we will see the overview of JSF, its architecture, life-cycle and comparison with other frameworks.

Introduction to the Java Server Faces – JSF

JSF is a Java Specification for the development of user interfaces in web application development in Java. You can go to the Java community process site to see JSF specification. JSF is used for the Interfaces designing of Java Based Web application. Complexity decreases with the use of JSF and Simplicity increases. It also defines a Component model with a particular cycle of request processing and delivering it back to the client or the user.JSF provide us the event-driven components. JSF follows MVC Architectural pattern, JSF Controls the View part of the web application, it provides an extra edge for the developers to remain focused on the view part of the application without touching or rendering the Controller or the Model part of the Web Application. We can also do the Server side validations with the help of JSF.

Overview of the JSF

JSF is nothing but a Framework to build a Java-based Used interfaces.

JSF provides a set of APIs to Perform Following tasks

  • Handling events
  • Validate inputs
  • Navigate to a page
  • Internationalization support
  • Accessibility support
  • Much more we will learn gradually

JSF Follows MVC pattern.

JSF can reside on the Client machine and it can also reside on the server depends on us the Developers, how we build our web app.

Why use JSF?

JSF is the Standard way of building GUI in Java-based Web applications.

JSF also Includes a large number of UI components that can be reused, which provides us the tags for tables, list elements or any HTML form.

JSF is Extendable, means a third party team can work for you, and you can easily integrate it within you web application.

Popular Third Party JSF component providers are OpenFaces, RichFaces, and PrimeFaces.

Application States can be managed with the help of JSF.

JSF can also be used to process form data and perform validations or conversions.

With the use of JSF, we can clearly separate the view part from the web application.

JSF and Servlets does not provide User Interface Component Model.

Who uses JSF?

JSf is used by the designer who creates the user interface of the web application; they should have knowledge of markup languages.

JSF is used by the Component Writers who creates the reusable components for future use.

JSF is used by the Developers who write the server side functionality which is not related to the interface development, this developer can make use of JSF for defining business logic and implementing event handlers.

JSF Versioning Details:

JSF inertial specification was released in 2004 and is has version id 1.o (JSF 1.0). JSF 2nd update was also in 2004 with bug fixes with no specification changes; this release has an Id of 1.1 (JSF 1.1). JSF third version was released in 2006, with core System and API enhancements and it has an Id of 1.2 (JSF 1.2). JSF fourth version was released in 2009, with improved functionality and performance issues resolved it has an Id of 2.0 (JSF 2.0). JSF fifth version was released in 2010. Actually it is the maintenance release of its previous version that is 2.o, it also has little specification changes it has an Id of 2.1 (JSF 2.1). JSF sixth version was released in 2013, with new concepts introduced like stateless views, page flows, etc. , it has an Id of 2.2 (JSF 2.2). As this post is written in 201, there is also a planned release in 2017

Facelets in JSF

Facelet is a bone for JSF, It is a powerful, lightweight page declaration language which is used to build JSF view using HTML, this is the simplest introduction to the facelet. It is used to build JSF view using HTML, the important thing to notice is that it is a lightweight page declaration language.

How JSF Works?

Client Sends a request, The interesting part of JSF is that the requests in JSF are the events, I means that an event at client side will send a request to the server, when the request arrives at the server it is structured in the UI Component Tree, this tree is used to make a response by the server, this response is in the form of markup language, which is then send back to the client. This all process will continue we clear when we discuss the JSF life-cycle which is also an important topic to discuss.

Getting Started with JSF

The only requirement for JSF is that we should have Java Development Kit 1.5 or above is installed. We will use Eclipse JEE for JSF and Tomcat server. For reference, you can see our tutorial “Set Up Environment for web development in Java.”We will also need these two jars “jsf-impl-<version>.jar” and “jsf-api-<version>.jar“.

Creating a Project for JSF

Go to the Project Explorer and right click –> select New –> click Other.

1 - start creating project

 

Find The Web and Expand it –> Select Dynamic Web Project –> click next

2 - selecting type of project to create

 

Name your project –> Select JSF version –> click next

3 - giving name and selecting JSF version2

 

select src and –> Click Next

4 - Select src Directory to build source

Click Next

5 - Next

 

If JSF library not present, you can also download it. Select JSF Library –> Click Finish

6 - Add JSF library

 

The created project directory will have this kind of directory structure.

7 - Directory Structure for JSF Application

Creating JSF File

To create a file Right Click on the Projects Web Content –> Select New –> Click HTML File

8 - Start Creating XHTML file

NOTE: name the file with extension “.xhtml”

Name your file –> Click Next.

9 - Naming File

Select New Facelet Composition Page –> Click Finish

10 - First Facelet Page to be created

XHTML file created but we did not need this code which is selected.

11 - Remove Selected Text from created File

 

Edit your file as Shown Below.

Try to Run on Server, Right Click on File –> Select RunAs –> Click RunOnServer the output will look like this.

12 -First Run of JSF - Output

Summary:

In this tutorial, we have accomplished following things.

  • Introduction to JSF
  • Overview of JSF
  • Why JSF
  • Who uses JSF
  • How JSF Works
  • JSF Version Details
  • JSF Getting Started

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

About Author

Uzair Ahmed Khan: 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 *