Adv - Java GTU Study Material Presentations Unit-5 Java Server Faces 2.0
Adv - Java GTU Study Material Presentations Unit-5 Java Server Faces 2.0
Advanced Java
Unit-5
Java Server Faces
Reference Book:
Black Book “ Java server programming” J2EE, 1st ed., Dream Tech Publishers,
2008. 3. Kathy walrath ”
Chapter 11
3
Unit-5 Java Server Faces 3 Darshan Institute of Engineering & Technology
What is JSF?
Java Server Faces (JSF) is a MVC web framework.
JSF simplifies the construction of user interfaces (UI) for server-
based applications by using reusable UI components in the page.
The JSF specification defines a set of standard UI components and
provides an (API) for developing components.
JSF enables the reuse and extension of the existing standard UI
components.
6
Unit-5 Java Server Faces 6 Darshan Institute of Engineering & Technology
What is MVC Design Pattern?
MVC design pattern designs an application using three separate
modules:
Model Model Carries Data and login
View Shows User Interface
Controller Handles processing of an application.
UI Logic Business Logic
View Model
Controller
Request & Relay data
8
Unit-5 Java Server Faces 8 Darshan Institute of Engineering & Technology
JSF Request Processing Life Cycle
JSF application lifecycle consist of six phases which are as follows:
Phase-I: Restore View (RV)
Phase-II: Apply Request Values (ARV)
Phase-III: Process Validations (PV)
Phase-IV: Update Model Values (UMV)
Phase-V: Invoke Application (IA)
Phase-IV: Render Response (RR)
Request Apply
Create or Process
Request
Restore View Validations
Values
Response
Render Invoke Update
Response Application Model Values
Request Apply
Create or Process
Request
Restore View Validations
Values
Response
Render Invoke Update
Response Application Model Values
Request Apply
Create or Process
Request
Restore View Validations
Values
Response
Render Invoke Update
Response Application Model Values
Request Apply
Create or Process
Request
Restore View Validations
Values
Response
Render Invoke Update
Response Application Model Values
Request Apply
Create or Process
Request
Restore View Validations
Values
Response
Render Invoke Update
Response Application Model Values
Request Apply
Create or Process
Request
Restore View Validations
Values
Response
Render Invoke Update
Response Application Model Values
29
Unit-5 Java Server Faces 29 Darshan Institute of Engineering & Technology
JSF Tag Libraries
JSF framework provides a standard HTML tag library.
Each tag will rendered into corresponding html output.
To use these html tags we have to use the following namespaces of URI in
html node.
<html xmlns="http://www.w3.org/1999/xhtml"
xmlns:h="http://java.sun.com/jsf/html">
Two types of JSF Tag library
18.</h:selectOneRadio>
1. import java.sql.*;
2. import javax.faces.bean.ManagedBean;
3. import javax.faces.bean.RequestScoped;
4. @ManagedBean
5. @RequestScoped
6. public class AuthenticationBean {
7. String uname;
8. String password;
9. public String getUname()
10. {return uname;}
11.public String getPassword()
12. {return password;}
13.public void setUname(String uname)
14. {this.uname = uname;}
15.public void setPassword(String password)
16. {this.password = password;}
8. <navigation-case>
9. <from-action>
#{authenticationBean.validateFromDB}</from-action>
10. <from-outcome>success</from-outcome>
11. <to-view-id>/success.xhtml</to-view-id>
12.</navigation-case>
13.<navigation-case>
14. <from-action>
#{authenticationBean.validateFromDB}</from-action>
15. <from-outcome>failure</from-outcome>
16. <to-view-id>/fail.xhtml</to-view-id>
17.</navigation-case>
18.</navigation-rule>
19.</faces-config>