JSF




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
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
Select dynamic web project

Step 2

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

jsf project name
jsf project name

Click Next.

 

Step 3

provide package name
provide package name

Click Next.

Step 4

Generate web.xml automatically.

generate web.xml
generate web.xml

Click Next.

Step 5

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

JSF library
JSF library

Select JSF library.

Select JSF library
Select JSF library.

Accept Licence and Click Finish.

Accept Software licence.
Accept Software licence.

Wait while it is downloading the JSF libraries.

downloading jsf library
downloading jsf library

Now Select the Library and click finish.

Select Library
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
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
add xhtml file

Provide File name.

xhtml file name
xhtml file name

Click Next.

xhtml template
xhtml template

Click Next.

jsf core
jsf core

Click Finish.

HelloWorldBean.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



	
		
		
    	   
    	    
    	   
    	
	
	

successmsg.xhtml



	
		

Hello World From

#{helloworldbean.fname} #{helloworldbean.lname}

download Code

Be the first to comment

Leave a Reply

Your email address will not be published.


*