JSF Tutorial

JSF Tutorial:-Overview

Java Server Faces is widely using in enterprise applications now a days.In this chapter we are just trying to give an overview  to JSF.Also we are demonstrating a very basic example.

What is JSF?

Java Server Faces or JSF is a Java Specifcation for developing server side user interfaces. JSF was developed through Java Community Process under JSR-314. The initial specification developed was the JSF 1.0 specification.The standard definition of JSF says “JavaServer Faces technology is a server-side component framework for building Java technology-based web applications “. JSF provides a well-defined programming model and various tag libraries. The tag libraries contain tag handlers that implement the component tags.

Parts of a JSF application

1)A number of web pages

2)Tags to add components to pages

3) Managed Beans:- They are POJOs intended for basic services like resource injection

4)A deployment description(web.xml)

5)Application configuration resource files(such as faces-config.xml):- They are optional .They are using for defining the page navigation rules and for defining components

6)Custom objects(Like validator objects) and custom tags created by the developer

JSF Implementations

1)Apache Myfaces

2)Mojarra JSF implementation

We are discussing a JSF example now.We are using Mojarra implementation in our example

JSF Example

Tools & Softwares needed

1)Java EE SDK

2)Eclipse IDE for Java EE developers

3)Apache Tomcat

4)Apache MyFaces libraries

Steps

1)Install all the required tools including Java EE SDK

2)Download the jstl librariesjstl-api-1.2 jar and jstl-impl-1.2 jar

3)Open eclipse IDE

4)Create a new dynamic web project.Give a suitable name to the project

1

5)Select configuration as JSF 2.2 configuration

2

6)Press next and then continue till the generate web.xml  page.Select the check box and press next

3

7)In the next section , we can download the Mojarra libraries from eclipse itself

mojara1

mojjara2

mojarra3

8)Then press Finish.

9)Now put the jstl jar files downloaded in step 2 to the WebContent/WEB-INF/lib folder of the project .

10)Create a Tomcat server instance and add the project to the server.We are using Tomcat 7 in this example.

addserver

11)Now create a managed bean for our example.In tis example we are creating a login page with text fields to enter the username and password. So our managed bean should have two attributes.So create a java file in any package in src

UserBean.java

12)Now create an xhtml file:- firstPage.xhtml in WebContent directory

firstPage.xhtml

We have two text fields and a button in this page .By clicking on the button in this page , navigation happens to the second page.Since this is a basic example , we are not having any navigation rules defined in faces-config.xml file.Those things we will be covering in the coming sections.

13)Now create the second xhtml file- : secondPage.xhtml

secondPage.xhtml

14)Ideally no changes are required in the web.xml for running this basic example , if we followed the steps.Also the faces-config.xml would be created automatically.It is the application configuration file in a JSF application.We will be using this file in our coming examples.

15)Now publish the web app by right clicking on the server instance and run the firstPage.xhtml.

runPage

16)Enter any values in the text fields.And press the button.The output page would be shown

successPage

    See Related Topics:

Navigation Rules in JSF

Leave a Reply

Your email address will not be published. Required fields are marked *

You may use these HTML tags and attributes: <a href="" title="" rel=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code class="" title="" data-url=""> <del datetime=""> <em> <i> <q cite=""> <s> <strike> <strong> <pre class="" title="" data-url=""> <span class="" title="" data-url="">