Monday, January 12, 2009

How to start JSF

Software required

1. Jboss-4.0.2
2. Eclipse Europa
3. JSF jar file (jsf-api.jar, jsf-impl.jar, jstl.jar, commons-beanutils.jar, commons-collections.jar, commons-digester.jar, commons-logging.jar)

1. Open Eclipse Europa with workspace C:\jsf_workspace
2. New -> project -> web -> Dynamic Web Project
3. Enter Project Name JSFDemo (You can give any name)
4. Click next -> next -> finish.

5. Go to Server Panel and add server, choose JBoss v4.0 -> Next -> Browse -> and choose the location of Jboss 4.0 server in your local driver (in my case C:/jboss4.0.2/jboss-4.0.2).

6. Next - > Next -> add your project JSFDemo -> Finish
7. Right click on server and start.

8. Right click on project -> propertise -> Java build Path -> Libraries -> Add external Jar and all the above metinoed jars.

9. Go to JSFDemo -> WebContent -> WEB-INF -> delete every thing from web.xml and put this below code

<?xml version="1.0" encoding="UTF-8"?>
<web-app id="WebApp_ID" version="2.4" xmlns="" xmlns:xsi="" xsi:schemaLocation="">


<servlet-name>Faces Servlet</servlet-name>


<servlet-name>Faces Servlet</servlet-name>

NOTE: Dont forget to add <listener> tag otherwise you will get below exception
javax.servlet.ServletException: Servlet.init() for servlet Faces Servlet threw exception 08:44:44,453 ERROR [[/JSFDemo]] StandardWrapper.Throwablejava.lang.NullPointerException at javax.faces.webapp.FacesServlet.init( at org.apache.catalina.core.StandardWrapper.loadServlet(

10. Unser WebContent create one file with name First.jsp and put this below code

<%@ page session="false" contentType="text/html;charset=utf-8"%>
<%@ taglib uri="" prefix="h"%>
<%@ taglib uri="" prefix="f"%>
<html> <title> JSF DEMO BY BINOD </title><body>
<h:form><h:outputText value="Binod Kumar Suman"> </h:outputText></h:form>

NOTE: No need to add any tld file in web.xml

11. If server is not started, please start the server
12. Open internet explorer and type http://localhost:8080/JSFDemo/First.jsf,

you will get output Binod Kumar Suman

Now I am showing that how you will get input from input page then process it and will show in another page. First create one POJO with properties as same as you will have in input form. Second have to use navigation concept means how to navigate one page to other page
For both you have to write one config.xml (faces-config.xml), this file must in the same folder where web.xml reside So, I am writing one application, that will accept the student name and city. After click on save record button, other page should display with insert info.
Create one entry jsp and one result jsp. But before that we should have one POJO class with student properties.
Create in one new package com.suman
package com.suman;
public class StudentVO {
private String name;
private int roll;
public String getName() {return name; }
public void setName(String name) { = name;}
public int getRoll() {return roll;}
public void setRoll(int roll) { this.roll = roll;}

Dont forget to put all java class in WEB-INF\classes

<%@ taglib uri="" prefix="h" %>
<%@ taglib uri="" prefix="f" %>
<html> <head><title>JSF DEMO BY BINOD</title></head>
<body> <h:form> <h1>
<h:outputText value="STUDENT ENTRY FORM"/></h1> <br> <h:outputText value="Please Enter Student Name "/>
<h:inputText value="#{}" /> <br>
<h:outputText value="Please Enter Stdent Roll"/>
<h:inputText value="#{StudentInfoBean.roll}" /> <br>
<h:commandButton action="result" value="Save Record" />
</h:form> </body></html>

NOTE: Here button action ("result" in this case) must same as <from-outcome> tag value in faces-config.xml

<%@ taglib uri="" prefix="h" %>
<%@ taglib uri="" prefix="f" %>
<html> <head><title>Result Page</title></head>
<body> <h3>
<h:outputText value="Student Name :: #{}" /> <h3>
<h:outputText value="Roll Number :: #{StudentInfoBean.roll}" />
</body> </html>


<?xml version="1.0"?>
<faces-config> <managed-bean>
</managed-bean> <navigation-rule>

Done every thing, clean the project and restart the server.
You code should work perfectly .................... :)

Properties file concept

Now I am showing that how to use the properties file to avoid all the hard code of button name, input box name.

Create one properties file in src folder (after complition should go into web-inf\classes folder) say
input_header=Student Entry Formprompt_student_name=Enter Student Name :: prompt_roll_number=Enter Student roll Number ::greeting_text=Welcome In IIM Bangalore button_text=Save Record
Now studentInfoEntry.jsp
<%@ taglib uri="" prefix="h" %>
<%@ taglib uri="" prefix="f" %>
<f:loadBundle basename="messages" var="message"/>
<title>JSF DEMO BY BINOD</title>
<body> <h:form> <h1>
<h:outputText value="#{message.input_header}"/></h1> <br> <h:outputText value="#{message.prompt_student_name}"/>
<h:inputText value="#{}" /> <br>
<h:outputText value="#{message.prompt_roll_number}"/>
<h:inputText value="#{StudentInfoBean.roll}" /> <br>
<h:commandButton action="result" value="#{message.button_text}" /> </h:form> </body>

Dont forget to add <f:loadBundle basename="messages" var="message"/> in all jsp file, where you are using properties value. Now see that how to put the validation in input values.

Wait for a good tutorial on JBOSS SEAM .................... :)


  1. hi,

    c:\jboss-seam-2.1.1.GA> seam generate

    here is small mistake, not 'seam generate' (thats in step 4) but 'seam deploy'

    great tutorial with all details !

  2. excellent tutorial man...keep it up:)

  3. It is very nice post.It is good post. It is simple and best. It helpful for future use.
    You can test your knowledge in html by attending HTML Quiz .