Introduction to JavaServer Faces (JSF)

Overview of the JavaServer Faces (JSF) component-based MVC framework for Java web applications with Managed Beans.

What is JSF?

JSF – JavaServer Faces is a java MVC framework for web application. It help us to make user interface with less code and time.

MVC and JSF

M – Model – Entity, Data, business layer.

V- View -JSp,jsf, xhtml page.

C- Controller – Managed bean.

How JSF works?

JSF project flow

Follow the below steps to setup JSF in eclipe.

Live Demo

Step 1

Open Eclipse (EE version). File ->New->Dynamic Web Project.

Select dynamic web project

Step 2

Provide project name. Select (configuration) JavaServer Faces v2.2 project.

jsf project name

Click Next.

Step 3

provide package name

Click Next.

Step 4

Generate web.xml automatically.

generate web.xml

Click Next.

Step 5

Select JSF library, if not available download by clicking on download button as shows below.

JSF library

Select JSF library.

Select JSF library.

Accept Licence and Click Finish.

Accept Software licence.

Wait while it is downloading the JSF libraries.

downloading jsf library

Now Select the Library and click finish.

Select Library

Note –

If you have JSF library in Local, no need to follow the Step 5 to download the JSF library, Just select and click Finish.

Step 6

Project Structure should be like below.

JSf project structure

Step 7

Add XHTML file. Write click on WebContent->New->XHTML.If you do not able to see the XHTML then add the XHTML plugin from market place.

add xhtml file

Provide File name.

xhtml file name

Click Next.

xhtml template

Click Next.

jsf core

Click Finish.

HelloWorldBean.java.

Java
package bean;

import java.io.Serializable;

public class HelloWorldBean implements Serializable{

	/**
	 * 
	 */
	private static final long serialVersionUID = 1L;
	
	private String fname;
	private String lname;
	public String getFname() {
		return fname;
	}
	public void setFname(String fname) {
		this.fname = fname;
	}
	public String getLname() {
		return lname;
	}
	public void setLname(String lname) {
		this.lname = lname;
	}

}

helloworld.xhtml

XML

successmsg.xhtml

XML
Hello World From #{helloworldbean.fname} #{helloworldbean.lname}
About Glenna Babshire29 Articles
Java & libraries writer. Writes the Java tutorials: the language from Java 21 on, encryption, configuration and the libraries around it.