Share on Google+Share on Google+

JSF 1.2 Simple Example

This section contains simple example using JSF 1.2. This is a startup tutorial for JSF beginners.

JSF 1.2 Simple Example

This section contains simple example using JSF 1.2. This is a startup tutorial for JSF beginners.


First create a project in eclipse as "HelloWorldJSF" & Select JavaServerFaces v1.2 Project under configuration as given below :

Click next and then again click next, following screen will appear :

If you already downloaded JSF 1.2 library , then select JSF 1.2 as above. But if you are doing it first time, click download library in the above window(right corner second icon)  and select JSF 1.2 for Apache as given below :

After downloading /selecting library click Finish.

Create a package name net.roseindia.jsf and create a class . The code of this managed bean  is given below

package net.roseindia.jsf;

public class HelloBean {
private int id;
private String name;

//Action method to add user
public String addUser() {

return "success";
public int getId() {
return id;
public void setId(int id) { = id;
public String getName() {
return name;
public void setName(String name) { = name;

Create the following JSP files under WebContent as follows :


<[email protected] uri="" prefix="f"%>
<[email protected] uri="" prefix="h"%>

<title>Add New User Form</title>
<h:message id="errors" for="User_ID" style="color:red"/>
<h:panelGrid border="1" columns="1">
<h:outputText value="Name"></h:outputText>
<h:inputText value="#{}"></h:inputText>
<h:commandButton action="#{helloBean.addUser}"
value="Add Customer"></h:commandButton>


<[email protected] uri="" prefix="f"%>
<[email protected] uri="" prefix="h"%>

<title>Hello Users</title>
<h:outputText value="HELLO !! #{}" style="font-size:22px;"></h:outputText>
<h3> Welcome to Roseindia !!</h3>

The configuration of faces-config.xml  as given below :

<?xml version="1.0" encoding="UTF-8"?>

<faces-config xmlns=""


When you execute application using the following URL :  http://localhost:8080/JSFHelloWorld/faces/AddUser.jsp  you will get the following output :

When you supply some name for example Roseindia, you will get the following output :

Download Source Code



Posted on: November 28, 2011 If you enjoyed this post then why not add us on Google+? Add us to your Circles

Share this Tutorial Follow us on Twitter, or add us on Facebook or Google Plus to keep you updated with the recent trends of Java and other open source platforms.

Discuss: JSF Simple Example  

Post your Comment

Your Name (*) :
Your Email :
Subject (*):
Your Comment (*):
  Reload Image
September 6, 2012
Thanks to RosIndia

very helpful code