SlideShare a Scribd company logo
1 of 31
Download to read offline
Java Server Faces
Fahad R. Golra
ECE Paris Ecole d'Ingรฉnieurs - FRANCE
Lecture 8 - Java Server Faces
(JSF)
โ€ข Introduction to JSF
โ€ข JSF Architecture
โ€ข JSF Lifecycle
โ€ข JSF Development Steps
2 JEE - Java Server Faces (JSF)
3 Layers of Information System
3 JEE - Java Server Faces (JSF)
presentation
layer
application logic
layer
resource management
layer
Client
informationsystem
EJB
JSP JSF
Servlets
JPA
Database
Java Server Faces
โ€ข JavaServer Faces technology is a server-side user
interface component framework for Java technology-
based web applications.
4 JEE - Java Server Faces (JSF)
Components of JSF
โ€ข An API for
โ€ข representing UI components and managing their state
โ€ข handling events
โ€ข server-side validation
โ€ข data conversion
โ€ข defining page navigation
โ€ข supporting internationalisation and accessibility
โ€ข Two JavaServer Pages (JSP) custom tag libraries for
expressing UI components within a JSP page and for
wiring components to server-side objects
5 JEE - Java Server Faces (JSF)
Why JSF ?
โ€ข Drop components onto a page by adding component
tags
โ€ข Wire component-generated events to server-side
application code
โ€ข Bind UI components on a page to server-side data
โ€ข Construct a UI with reusable and extensible
components
โ€ข Save and restore UI state beyond the life of server
requests
6 JEE - Java Server Faces (JSF)
Request Scope
7 JEE - Java Server Faces (JSF)
client
Serverrequest
response Request Scope
request
response Request Scope
client 2
request
response Request Scope
perrequestperrequest
Session Scope
8 JEE - Java Server Faces (JSF)
client
Serverrequest
response
Session Scope
request
response
client 2
request
response
Session Scope
perclientperclient
Application Scope
9 JEE - Java Server Faces (JSF)
client
Serverrequest
response
Application Scope
request
response
client 2
request
response
perapplication
JSF Architecture
10 JEE - Java Server Faces (JSF)
JSF User Interface
โ€ข The UI for the web application manages the objects referenced by the
JSP page.
โ€ข These objects include
โ€ข The UI component objects that map to the tags on the JSP page
โ€ข Any event listeners, validators, and converters that are registered on the
components
โ€ข The JavaBeans components that encapsulate the data and application-
specific functionality of the components
11 JEE - Java Server Faces (JSF)
JSF Lifecycle
12 JEE - Java Server Faces (JSF)
Client Browser
client
Restore Value
Re-constitute component
tree
Apply Request
Values
Process Events,
Validators
Render Response
Invoke Application
Logic
Update Model
Values
Restore View Phase
โ€ข JSF implementation
โ€ข builds the view of the page
โ€ข wires event handlers and validators to components in the
view
โ€ข saves the view in the FacesContext instance
โ€ข Initial Request - creates an empty view, advances to
the render response phase
โ€ข Subsequent Request - restores the (already existing)
view by using the state information saved on the
client or the server
13 JEE - Java Server Faces (JSF)
Apply Request Values Phase
โ€ข Each component in the tree extracts its new value from the
request parameters by using its decode method
โ€ข Implementation skips to the render response phase if
renderResponse is called
โ€ข If events have been queued, the they are broadcasted to
interested listeners
โ€ข validation, conversion, and events associated with
components having immediate attributes will be processed
during this phase
14 JEE - Java Server Faces (JSF)
Process Event, Validators Phase
โ€ข JavaServer Faces implementation processes all
validators registered on the components in the tree
โ€ข If validation fails, error message is added to
FacesContext
โ€ข Events from previous phase and this phase are used to render
errors by advancing to render response phase
โ€ข Implementation skips to the render response phase if
renderResponse is called
โ€ข If events have been queued, the they are broadcasted to
interested listeners
15 JEE - Java Server Faces (JSF)
Update Model Values Phase
โ€ข If data is valid, the implementation can traverse the
component tree and set the corresponding server-side
object properties to the componentsโ€™ local values.
โ€ข Implementation will update the bean properties
pointed at by an input componentโ€™s value attribute.
โ€ข Implementation skips to the render response phase to
display any error messages
โ€ข If events have been queued, the they are broadcasted to
interested listeners
16 JEE - Java Server Faces (JSF)
Invoke Application Logic Phase
โ€ข JSF implementation handles any application-level
events, such as submitting a form or linking to
another page
โ€ข If the view being processed was reconstructed from
state information from a previous request and if a
component has fired an event, these events are
broadcast to interested listeners.
17 JEE - Java Server Faces (JSF)
Render Response Phase
โ€ข JSF implementation delegates authority for rendering the
page to the JSP container if the application is using JSP
pages.
โ€ข For initial request, the components represented on the page
will be added to the component tree
โ€ข components donโ€™t need to added again for subsequent
requests
โ€ข Components will be rendered as the JSP container
traverses the tags in the page.
โ€ข queued error messages are displayed, if any
โ€ข Once rendered, the state of the response is saved so that
subsequent requests can access it
18 JEE - Java Server Faces (JSF)
UI Components
โ€ข UIComponent/UIComponentBase
โ€ข Base class for all user interface components
โ€ข Standard UIComponent Subclasses
โ€ข UICommand, UIForm, UIOutput
โ€ข UIGraphic, UIInput, UIPanel, UIParameter
โ€ข UISelectBoolean, UISelectMany, UISelectOne
โ€ข Example
<h:inputText id=โ€œfNameInput"
value="#{UserRegistrationBean.firstName}"/>
19 JEE - Java Server Faces (JSF)
JSF Validators
โ€ข Validatorsโ€”Perform correctness checks on UIInput
values
โ€ข Register one or more per component
โ€ข Enqueue one or more messages on errors
โ€ข Standard implementations for common cases
โ€ข Example
<h:input_text valueRef=โ€testingBean.todayโ€
<f:validator_length minimum=โ€6โ€ maximum='10โ€ />
20 JEE - Java Server Faces (JSF)
JSF Converters
โ€ข Convertersโ€”Plug-in for conversions:
โ€ข Output: Object to String
โ€ข Input: String to Object
โ€ข Standard implementations for common cases
โ€ข Example
<h:input_text valueRef=โ€testingBean.todayโ€
convertor=โ€DateTimeโ€/>
21 JEE - Java Server Faces (JSF)
Navigation
โ€ข Application developer defines the navigation model of
the web application
โ€ข in Application configuration file (Facesconfig.xml)
โ€ข Navigation rules
โ€ข Determine where (page) to go.
โ€ข Precise navigation case
22 JEE - Java Server Faces (JSF)
JSF Development Steps
1. Build Model from Java Beans
โ€ข Lifetime Configured by developer and managed by JSF
โ€ข Request, Session, or Application Scope
โ€ข Setters and getters accessed through JSF pages
2. Add model objects (managed bean) declarations to
Application Configuration File faces-config.xml
3. Use UI Components to build JSF pages
โ€ข Include JSF Tags, Validation and Event Listeners
4. Define Page Navigation rules in faces.config.xml
5. Configure web.xml
23 JEE - Java Server Faces (JSF)
Step 1 - Build Model
โ€ข The model (M) in MVC
โ€ข A regular JavaBeans with getters / setters
โ€ข May contain application methods and event handlers
โ€ข Use to hold data from a UI (page)
โ€ข Creation and lifetime is managed by JSF runtime
โ€ข application, session, request
โ€ข JSF keeps the bean's data in sync with the UI
24 JEE - Java Server Faces (JSF)
Step 2 - Declare Model Objects
โ€ข In Faces-config.xml
<managed-bean>
<managed-bean-name>
LoginFormBean
</managed-bean-name>
<managed-bean-class>
myapp.LoginFormBean
</managed-bean-class>
<managed-bean-scope>
request
</managed-bean-scope>
</managed-bean>
25 JEE - Java Server Faces (JSF)
Step 3 - Create JSF Pages
โ€ข Must include JSF tag library
โ€ข HTML and core tags
โ€ข All JSF tags must enclosed between a set of view tag
โ€ข Use JSF form and form component tags
โ€ข <h:input_text> not <input type=โ€textโ€>
โ€ข <h:command_button> not <input type=โ€submitโ€>
โ€ข May include validators and event listeners on any
form components
26 JEE - Java Server Faces (JSF)
Step 3 - Create JSF Pages
<f:view>
<f:form formName=โ€logonFormโ€>
<h:panel_grid columns=โ€2โ€>
<h:output_text value=โ€Username:โ€/>
<h:input_text id=โ€usernameโ€ length=โ€16โ€
valueRef=โ€logonBean.usernameโ€/>
<h:output_text value=โ€Password:โ€/>
<h:input_secret id=โ€passwordโ€ length=โ€16โ€
valueRef=โ€logonBean.passwordโ€/>
<h:command_button type=โ€submitโ€ label=โ€Log Onโ€
actionRef=โ€logonBean.logonโ€/>
<h:command_button type=โ€resetโ€ label=โ€Resetโ€/>
</h:panel_grid>
</f:form>
</f:view>
27
Step 4 - Define Navigation
<navigation-rule>
<from-tree-id> /login.jsp </from-tree-id>
<navigation-case>
<from-outcome>success</from-outcome>
<to-tree-id>/menu.jsp</to-tree-id>
</navigation-case>
<navigation-case>
<from-outcome>failed</from-outcome>
<to-tree-id>/error.jsp</to-tree-id>
</navigation-case>
</navigation-rule>
28 JEE - Java Server Faces (JSF)
Step 5 - Configure Web.xml
<context-param>
<param-name>
javax.faces.application.CONFIG_FILES
</param-name>
<param-value>/WEB-INF/faces-config.xml
</param-value>
</context-param>
<servlet>
<servlet-name>Faces Servlet</servlet-name>
<servlet-class>
javax.faces.webapp.FacesServlet</servlet-class>
<load-on-startup> 1 </load-on-startup>
</servlet>
<!-- Faces Servlet Mapping -->
<servlet-mapping>
<servlet-name>Faces Servlet</servlet-name>
<url-pattern>/faces/*</url-pattern>
</servlet-mapping>
29 JEE - Java Server Faces (JSF)
JSF vs. JSP for UI
30
JSF JSP
Components โ€ข Rich UI-data-bound
components with events
provided
โ€ข Custom components
โ€ข Standard tags (JSTL) that are
non-UI and very basic
โ€ข Custom components through
tag libraries
Device
independence
โ€ข Reader kits that provide
device independence
โ€ข None
Error handling
and validation
โ€ข Validation framework
โ€ข Many predefined validators
โ€ข None
Scripting โ€ข Scripts can be attached to
events
โ€ข All components accessible
from scripts
โ€ข Embedded Java in the page
Page flow โ€ข Simple navigation file (faces-
config.xml)
โ€ข None
31 JEE - Java Server Faces (JSF)

More Related Content

What's hot

Internet programming lab manual
Internet programming lab manualInternet programming lab manual
Internet programming lab manual
inteldualcore
ย 

What's hot (20)

Difference between complete,ordered,full,strict,perfect and balanced binary tree
Difference between complete,ordered,full,strict,perfect and balanced binary treeDifference between complete,ordered,full,strict,perfect and balanced binary tree
Difference between complete,ordered,full,strict,perfect and balanced binary tree
ย 
Online Admission System
Online Admission System  Online Admission System
Online Admission System
ย 
Enterprise JavaBeans(EJB)
Enterprise JavaBeans(EJB)Enterprise JavaBeans(EJB)
Enterprise JavaBeans(EJB)
ย 
College management system ppt
College management system pptCollege management system ppt
College management system ppt
ย 
Database basics
Database basicsDatabase basics
Database basics
ย 
MYSQL - PHP Database Connectivity
MYSQL - PHP Database ConnectivityMYSQL - PHP Database Connectivity
MYSQL - PHP Database Connectivity
ย 
Database replication
Database replicationDatabase replication
Database replication
ย 
MYSQL.ppt
MYSQL.pptMYSQL.ppt
MYSQL.ppt
ย 
Php with MYSQL Database
Php with MYSQL DatabasePhp with MYSQL Database
Php with MYSQL Database
ย 
An Overview of Web Services: SOAP and REST
An Overview of Web Services: SOAP and REST An Overview of Web Services: SOAP and REST
An Overview of Web Services: SOAP and REST
ย 
ASP.NET Lecture 1
ASP.NET Lecture 1ASP.NET Lecture 1
ASP.NET Lecture 1
ย 
Lecture-1: Introduction to web engineering - course overview and grading scheme
Lecture-1: Introduction to web engineering - course overview and grading schemeLecture-1: Introduction to web engineering - course overview and grading scheme
Lecture-1: Introduction to web engineering - course overview and grading scheme
ย 
Data Models [DATABASE SYSTEMS: Design, Implementation, and Management]
Data Models [DATABASE SYSTEMS: Design, Implementation, and Management]Data Models [DATABASE SYSTEMS: Design, Implementation, and Management]
Data Models [DATABASE SYSTEMS: Design, Implementation, and Management]
ย 
Systems Analysis and Design | Final Project
Systems Analysis and Design | Final Project Systems Analysis and Design | Final Project
Systems Analysis and Design | Final Project
ย 
Internet programming lab manual
Internet programming lab manualInternet programming lab manual
Internet programming lab manual
ย 
ASP.NET 07 - Site Navigation
ASP.NET 07 - Site NavigationASP.NET 07 - Site Navigation
ASP.NET 07 - Site Navigation
ย 
Database connectivity and web technologies
Database connectivity and web technologiesDatabase connectivity and web technologies
Database connectivity and web technologies
ย 
XML and XML Applications - Lecture 04 - Web Information Systems (WE-DINF-11912)
XML and XML Applications - Lecture 04 - Web Information Systems (WE-DINF-11912)XML and XML Applications - Lecture 04 - Web Information Systems (WE-DINF-11912)
XML and XML Applications - Lecture 04 - Web Information Systems (WE-DINF-11912)
ย 
Can You Do That with APEX? Building Not So Straightforward Pages
Can You Do That with APEX? Building Not So Straightforward PagesCan You Do That with APEX? Building Not So Straightforward Pages
Can You Do That with APEX? Building Not So Straightforward Pages
ย 
Webservices in SalesForce (part 1)
Webservices in SalesForce (part 1)Webservices in SalesForce (part 1)
Webservices in SalesForce (part 1)
ย 

Similar to Lecture 10 - Java Server Faces (JSF)

Contextual Dependency Injection for Apachecon 2010
Contextual Dependency Injection for Apachecon 2010Contextual Dependency Injection for Apachecon 2010
Contextual Dependency Injection for Apachecon 2010
Rohit Kelapure
ย 

Similar to Lecture 10 - Java Server Faces (JSF) (20)

Java EE 8 Web Frameworks: A Look at JSF vs MVC
Java EE 8 Web Frameworks: A Look at JSF vs MVCJava EE 8 Web Frameworks: A Look at JSF vs MVC
Java EE 8 Web Frameworks: A Look at JSF vs MVC
ย 
JSF.pptx
JSF.pptxJSF.pptx
JSF.pptx
ย 
Java server faces
Java server facesJava server faces
Java server faces
ย 
Jsfsunum
JsfsunumJsfsunum
Jsfsunum
ย 
JSF2
JSF2JSF2
JSF2
ย 
Introduction to jsf 2
Introduction to jsf 2Introduction to jsf 2
Introduction to jsf 2
ย 
JSF basics
JSF basicsJSF basics
JSF basics
ย 
Jsfsunum
JsfsunumJsfsunum
Jsfsunum
ย 
AK 5 JSF 21 july 2008
AK 5 JSF   21 july 2008AK 5 JSF   21 july 2008
AK 5 JSF 21 july 2008
ย 
AK 4 JSF
AK 4 JSFAK 4 JSF
AK 4 JSF
ย 
Jsf presentation
Jsf presentationJsf presentation
Jsf presentation
ย 
Jsf 2
Jsf 2Jsf 2
Jsf 2
ย 
In The Brain of Cagatay Civici: Exploring JavaServer Faces 2.0 and PrimeFaces
In The Brain of Cagatay Civici: Exploring JavaServer Faces 2.0 and PrimeFaces In The Brain of Cagatay Civici: Exploring JavaServer Faces 2.0 and PrimeFaces
In The Brain of Cagatay Civici: Exploring JavaServer Faces 2.0 and PrimeFaces
ย 
PUC SE Day 2019 - SpringBoot
PUC SE Day 2019 - SpringBootPUC SE Day 2019 - SpringBoot
PUC SE Day 2019 - SpringBoot
ย 
Contextual Dependency Injection for Apachecon 2010
Contextual Dependency Injection for Apachecon 2010Contextual Dependency Injection for Apachecon 2010
Contextual Dependency Injection for Apachecon 2010
ย 
Jsf
JsfJsf
Jsf
ย 
Glassfish JEE Server Administration - JEE Introduction
Glassfish JEE Server Administration - JEE IntroductionGlassfish JEE Server Administration - JEE Introduction
Glassfish JEE Server Administration - JEE Introduction
ย 
InterConnect 2016 Java EE 7 Overview (PEJ-5296)
InterConnect 2016 Java EE 7 Overview (PEJ-5296)InterConnect 2016 Java EE 7 Overview (PEJ-5296)
InterConnect 2016 Java EE 7 Overview (PEJ-5296)
ย 
Jsf
JsfJsf
Jsf
ย 
Mastering OmniFaces - A Problem to Solution Approach
Mastering OmniFaces - A Problem to Solution ApproachMastering OmniFaces - A Problem to Solution Approach
Mastering OmniFaces - A Problem to Solution Approach
ย 

More from Fahad Golra

Seance 3- Programmation en langage C
Seance 3- Programmation en langage C Seance 3- Programmation en langage C
Seance 3- Programmation en langage C
Fahad Golra
ย 
Deviation Detection in Process Enactment
Deviation Detection in Process EnactmentDeviation Detection in Process Enactment
Deviation Detection in Process Enactment
Fahad Golra
ย 
Meta l metacase tools & possibilities
Meta l metacase tools & possibilitiesMeta l metacase tools & possibilities
Meta l metacase tools & possibilities
Fahad Golra
ย 

More from Fahad Golra (19)

Seance 4- Programmation en langage C
Seance 4- Programmation en langage CSeance 4- Programmation en langage C
Seance 4- Programmation en langage C
ย 
Seance 3- Programmation en langage C
Seance 3- Programmation en langage C Seance 3- Programmation en langage C
Seance 3- Programmation en langage C
ย 
Seance 2 - Programmation en langage C
Seance 2 - Programmation en langage CSeance 2 - Programmation en langage C
Seance 2 - Programmation en langage C
ย 
Seance 1 - Programmation en langage C
Seance 1 - Programmation en langage CSeance 1 - Programmation en langage C
Seance 1 - Programmation en langage C
ย 
Tutorial 4 - Basics of Digital Photography
Tutorial 4 - Basics of Digital PhotographyTutorial 4 - Basics of Digital Photography
Tutorial 4 - Basics of Digital Photography
ย 
Tutorial 3 - Basics of Digital Photography
Tutorial 3 - Basics of Digital PhotographyTutorial 3 - Basics of Digital Photography
Tutorial 3 - Basics of Digital Photography
ย 
Tutorial 2 - Basics of Digital Photography
Tutorial 2 - Basics of Digital PhotographyTutorial 2 - Basics of Digital Photography
Tutorial 2 - Basics of Digital Photography
ย 
Tutorial 1 - Basics of Digital Photography
Tutorial 1 - Basics of Digital PhotographyTutorial 1 - Basics of Digital Photography
Tutorial 1 - Basics of Digital Photography
ย 
Lecture 9 - Java Persistence, JPA 2
Lecture 9 - Java Persistence, JPA 2Lecture 9 - Java Persistence, JPA 2
Lecture 9 - Java Persistence, JPA 2
ย 
Lecture 8 Enterprise Java Beans (EJB)
Lecture 8  Enterprise Java Beans (EJB)Lecture 8  Enterprise Java Beans (EJB)
Lecture 8 Enterprise Java Beans (EJB)
ย 
Lecture 7 Web Services JAX-WS & JAX-RS
Lecture 7   Web Services JAX-WS & JAX-RSLecture 7   Web Services JAX-WS & JAX-RS
Lecture 7 Web Services JAX-WS & JAX-RS
ย 
Lecture 6 Web Sockets
Lecture 6   Web SocketsLecture 6   Web Sockets
Lecture 6 Web Sockets
ย 
Lecture 5 JSTL, custom tags, maven
Lecture 5   JSTL, custom tags, mavenLecture 5   JSTL, custom tags, maven
Lecture 5 JSTL, custom tags, maven
ย 
Lecture 4: JavaServer Pages (JSP) & Expression Language (EL)
Lecture 4:  JavaServer Pages (JSP) & Expression Language (EL)Lecture 4:  JavaServer Pages (JSP) & Expression Language (EL)
Lecture 4: JavaServer Pages (JSP) & Expression Language (EL)
ย 
Lecture 2: Servlets
Lecture 2:  ServletsLecture 2:  Servlets
Lecture 2: Servlets
ย 
Lecture 1: Introduction to JEE
Lecture 1:  Introduction to JEELecture 1:  Introduction to JEE
Lecture 1: Introduction to JEE
ย 
Lecture 3: Servlets - Session Management
Lecture 3:  Servlets - Session ManagementLecture 3:  Servlets - Session Management
Lecture 3: Servlets - Session Management
ย 
Deviation Detection in Process Enactment
Deviation Detection in Process EnactmentDeviation Detection in Process Enactment
Deviation Detection in Process Enactment
ย 
Meta l metacase tools & possibilities
Meta l metacase tools & possibilitiesMeta l metacase tools & possibilities
Meta l metacase tools & possibilities
ย 

Recently uploaded

CALL ON โžฅ8923113531 ๐Ÿ”Call Girls Kakori Lucknow best sexual service Online โ˜‚๏ธ
CALL ON โžฅ8923113531 ๐Ÿ”Call Girls Kakori Lucknow best sexual service Online  โ˜‚๏ธCALL ON โžฅ8923113531 ๐Ÿ”Call Girls Kakori Lucknow best sexual service Online  โ˜‚๏ธ
CALL ON โžฅ8923113531 ๐Ÿ”Call Girls Kakori Lucknow best sexual service Online โ˜‚๏ธ
anilsa9823
ย 
Hand gesture recognition PROJECT PPT.pptx
Hand gesture recognition PROJECT PPT.pptxHand gesture recognition PROJECT PPT.pptx
Hand gesture recognition PROJECT PPT.pptx
bodapatigopi8531
ย 
CALL ON โžฅ8923113531 ๐Ÿ”Call Girls Badshah Nagar Lucknow best Female service
CALL ON โžฅ8923113531 ๐Ÿ”Call Girls Badshah Nagar Lucknow best Female serviceCALL ON โžฅ8923113531 ๐Ÿ”Call Girls Badshah Nagar Lucknow best Female service
CALL ON โžฅ8923113531 ๐Ÿ”Call Girls Badshah Nagar Lucknow best Female service
anilsa9823
ย 
+971565801893>>SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHAB...
+971565801893>>SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHAB...+971565801893>>SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHAB...
+971565801893>>SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHAB...
Health
ย 

Recently uploaded (20)

How To Troubleshoot Collaboration Apps for the Modern Connected Worker
How To Troubleshoot Collaboration Apps for the Modern Connected WorkerHow To Troubleshoot Collaboration Apps for the Modern Connected Worker
How To Troubleshoot Collaboration Apps for the Modern Connected Worker
ย 
Steps To Getting Up And Running Quickly With MyTimeClock Employee Scheduling ...
Steps To Getting Up And Running Quickly With MyTimeClock Employee Scheduling ...Steps To Getting Up And Running Quickly With MyTimeClock Employee Scheduling ...
Steps To Getting Up And Running Quickly With MyTimeClock Employee Scheduling ...
ย 
The Real-World Challenges of Medical Device Cybersecurity- Mitigating Vulnera...
The Real-World Challenges of Medical Device Cybersecurity- Mitigating Vulnera...The Real-World Challenges of Medical Device Cybersecurity- Mitigating Vulnera...
The Real-World Challenges of Medical Device Cybersecurity- Mitigating Vulnera...
ย 
Unlocking the Future of AI Agents with Large Language Models
Unlocking the Future of AI Agents with Large Language ModelsUnlocking the Future of AI Agents with Large Language Models
Unlocking the Future of AI Agents with Large Language Models
ย 
Try MyIntelliAccount Cloud Accounting Software As A Service Solution Risk Fre...
Try MyIntelliAccount Cloud Accounting Software As A Service Solution Risk Fre...Try MyIntelliAccount Cloud Accounting Software As A Service Solution Risk Fre...
Try MyIntelliAccount Cloud Accounting Software As A Service Solution Risk Fre...
ย 
Optimizing AI for immediate response in Smart CCTV
Optimizing AI for immediate response in Smart CCTVOptimizing AI for immediate response in Smart CCTV
Optimizing AI for immediate response in Smart CCTV
ย 
call girls in Vaishali (Ghaziabad) ๐Ÿ” >เผ’8448380779 ๐Ÿ” genuine Escort Service ๐Ÿ”โœ”๏ธโœ”๏ธ
call girls in Vaishali (Ghaziabad) ๐Ÿ” >เผ’8448380779 ๐Ÿ” genuine Escort Service ๐Ÿ”โœ”๏ธโœ”๏ธcall girls in Vaishali (Ghaziabad) ๐Ÿ” >เผ’8448380779 ๐Ÿ” genuine Escort Service ๐Ÿ”โœ”๏ธโœ”๏ธ
call girls in Vaishali (Ghaziabad) ๐Ÿ” >เผ’8448380779 ๐Ÿ” genuine Escort Service ๐Ÿ”โœ”๏ธโœ”๏ธ
ย 
The Ultimate Test Automation Guide_ Best Practices and Tips.pdf
The Ultimate Test Automation Guide_ Best Practices and Tips.pdfThe Ultimate Test Automation Guide_ Best Practices and Tips.pdf
The Ultimate Test Automation Guide_ Best Practices and Tips.pdf
ย 
Tech Tuesday-Harness the Power of Effective Resource Planning with OnePlanโ€™s ...
Tech Tuesday-Harness the Power of Effective Resource Planning with OnePlanโ€™s ...Tech Tuesday-Harness the Power of Effective Resource Planning with OnePlanโ€™s ...
Tech Tuesday-Harness the Power of Effective Resource Planning with OnePlanโ€™s ...
ย 
SyndBuddy AI 2k Review 2024: Revolutionizing Content Syndication with AI
SyndBuddy AI 2k Review 2024: Revolutionizing Content Syndication with AISyndBuddy AI 2k Review 2024: Revolutionizing Content Syndication with AI
SyndBuddy AI 2k Review 2024: Revolutionizing Content Syndication with AI
ย 
Reassessing the Bedrock of Clinical Function Models: An Examination of Large ...
Reassessing the Bedrock of Clinical Function Models: An Examination of Large ...Reassessing the Bedrock of Clinical Function Models: An Examination of Large ...
Reassessing the Bedrock of Clinical Function Models: An Examination of Large ...
ย 
Unveiling the Tech Salsa of LAMs with Janus in Real-Time Applications
Unveiling the Tech Salsa of LAMs with Janus in Real-Time ApplicationsUnveiling the Tech Salsa of LAMs with Janus in Real-Time Applications
Unveiling the Tech Salsa of LAMs with Janus in Real-Time Applications
ย 
Short Story: Unveiling the Reasoning Abilities of Large Language Models by Ke...
Short Story: Unveiling the Reasoning Abilities of Large Language Models by Ke...Short Story: Unveiling the Reasoning Abilities of Large Language Models by Ke...
Short Story: Unveiling the Reasoning Abilities of Large Language Models by Ke...
ย 
CALL ON โžฅ8923113531 ๐Ÿ”Call Girls Kakori Lucknow best sexual service Online โ˜‚๏ธ
CALL ON โžฅ8923113531 ๐Ÿ”Call Girls Kakori Lucknow best sexual service Online  โ˜‚๏ธCALL ON โžฅ8923113531 ๐Ÿ”Call Girls Kakori Lucknow best sexual service Online  โ˜‚๏ธ
CALL ON โžฅ8923113531 ๐Ÿ”Call Girls Kakori Lucknow best sexual service Online โ˜‚๏ธ
ย 
Hand gesture recognition PROJECT PPT.pptx
Hand gesture recognition PROJECT PPT.pptxHand gesture recognition PROJECT PPT.pptx
Hand gesture recognition PROJECT PPT.pptx
ย 
Diamond Application Development Crafting Solutions with Precision
Diamond Application Development Crafting Solutions with PrecisionDiamond Application Development Crafting Solutions with Precision
Diamond Application Development Crafting Solutions with Precision
ย 
Right Money Management App For Your Financial Goals
Right Money Management App For Your Financial GoalsRight Money Management App For Your Financial Goals
Right Money Management App For Your Financial Goals
ย 
CALL ON โžฅ8923113531 ๐Ÿ”Call Girls Badshah Nagar Lucknow best Female service
CALL ON โžฅ8923113531 ๐Ÿ”Call Girls Badshah Nagar Lucknow best Female serviceCALL ON โžฅ8923113531 ๐Ÿ”Call Girls Badshah Nagar Lucknow best Female service
CALL ON โžฅ8923113531 ๐Ÿ”Call Girls Badshah Nagar Lucknow best Female service
ย 
5 Signs You Need a Fashion PLM Software.pdf
5 Signs You Need a Fashion PLM Software.pdf5 Signs You Need a Fashion PLM Software.pdf
5 Signs You Need a Fashion PLM Software.pdf
ย 
+971565801893>>SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHAB...
+971565801893>>SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHAB...+971565801893>>SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHAB...
+971565801893>>SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHAB...
ย 

Lecture 10 - Java Server Faces (JSF)

  • 1. Java Server Faces Fahad R. Golra ECE Paris Ecole d'Ingรฉnieurs - FRANCE
  • 2. Lecture 8 - Java Server Faces (JSF) โ€ข Introduction to JSF โ€ข JSF Architecture โ€ข JSF Lifecycle โ€ข JSF Development Steps 2 JEE - Java Server Faces (JSF)
  • 3. 3 Layers of Information System 3 JEE - Java Server Faces (JSF) presentation layer application logic layer resource management layer Client informationsystem EJB JSP JSF Servlets JPA Database
  • 4. Java Server Faces โ€ข JavaServer Faces technology is a server-side user interface component framework for Java technology- based web applications. 4 JEE - Java Server Faces (JSF)
  • 5. Components of JSF โ€ข An API for โ€ข representing UI components and managing their state โ€ข handling events โ€ข server-side validation โ€ข data conversion โ€ข defining page navigation โ€ข supporting internationalisation and accessibility โ€ข Two JavaServer Pages (JSP) custom tag libraries for expressing UI components within a JSP page and for wiring components to server-side objects 5 JEE - Java Server Faces (JSF)
  • 6. Why JSF ? โ€ข Drop components onto a page by adding component tags โ€ข Wire component-generated events to server-side application code โ€ข Bind UI components on a page to server-side data โ€ข Construct a UI with reusable and extensible components โ€ข Save and restore UI state beyond the life of server requests 6 JEE - Java Server Faces (JSF)
  • 7. Request Scope 7 JEE - Java Server Faces (JSF) client Serverrequest response Request Scope request response Request Scope client 2 request response Request Scope perrequestperrequest
  • 8. Session Scope 8 JEE - Java Server Faces (JSF) client Serverrequest response Session Scope request response client 2 request response Session Scope perclientperclient
  • 9. Application Scope 9 JEE - Java Server Faces (JSF) client Serverrequest response Application Scope request response client 2 request response perapplication
  • 10. JSF Architecture 10 JEE - Java Server Faces (JSF)
  • 11. JSF User Interface โ€ข The UI for the web application manages the objects referenced by the JSP page. โ€ข These objects include โ€ข The UI component objects that map to the tags on the JSP page โ€ข Any event listeners, validators, and converters that are registered on the components โ€ข The JavaBeans components that encapsulate the data and application- specific functionality of the components 11 JEE - Java Server Faces (JSF)
  • 12. JSF Lifecycle 12 JEE - Java Server Faces (JSF) Client Browser client Restore Value Re-constitute component tree Apply Request Values Process Events, Validators Render Response Invoke Application Logic Update Model Values
  • 13. Restore View Phase โ€ข JSF implementation โ€ข builds the view of the page โ€ข wires event handlers and validators to components in the view โ€ข saves the view in the FacesContext instance โ€ข Initial Request - creates an empty view, advances to the render response phase โ€ข Subsequent Request - restores the (already existing) view by using the state information saved on the client or the server 13 JEE - Java Server Faces (JSF)
  • 14. Apply Request Values Phase โ€ข Each component in the tree extracts its new value from the request parameters by using its decode method โ€ข Implementation skips to the render response phase if renderResponse is called โ€ข If events have been queued, the they are broadcasted to interested listeners โ€ข validation, conversion, and events associated with components having immediate attributes will be processed during this phase 14 JEE - Java Server Faces (JSF)
  • 15. Process Event, Validators Phase โ€ข JavaServer Faces implementation processes all validators registered on the components in the tree โ€ข If validation fails, error message is added to FacesContext โ€ข Events from previous phase and this phase are used to render errors by advancing to render response phase โ€ข Implementation skips to the render response phase if renderResponse is called โ€ข If events have been queued, the they are broadcasted to interested listeners 15 JEE - Java Server Faces (JSF)
  • 16. Update Model Values Phase โ€ข If data is valid, the implementation can traverse the component tree and set the corresponding server-side object properties to the componentsโ€™ local values. โ€ข Implementation will update the bean properties pointed at by an input componentโ€™s value attribute. โ€ข Implementation skips to the render response phase to display any error messages โ€ข If events have been queued, the they are broadcasted to interested listeners 16 JEE - Java Server Faces (JSF)
  • 17. Invoke Application Logic Phase โ€ข JSF implementation handles any application-level events, such as submitting a form or linking to another page โ€ข If the view being processed was reconstructed from state information from a previous request and if a component has fired an event, these events are broadcast to interested listeners. 17 JEE - Java Server Faces (JSF)
  • 18. Render Response Phase โ€ข JSF implementation delegates authority for rendering the page to the JSP container if the application is using JSP pages. โ€ข For initial request, the components represented on the page will be added to the component tree โ€ข components donโ€™t need to added again for subsequent requests โ€ข Components will be rendered as the JSP container traverses the tags in the page. โ€ข queued error messages are displayed, if any โ€ข Once rendered, the state of the response is saved so that subsequent requests can access it 18 JEE - Java Server Faces (JSF)
  • 19. UI Components โ€ข UIComponent/UIComponentBase โ€ข Base class for all user interface components โ€ข Standard UIComponent Subclasses โ€ข UICommand, UIForm, UIOutput โ€ข UIGraphic, UIInput, UIPanel, UIParameter โ€ข UISelectBoolean, UISelectMany, UISelectOne โ€ข Example <h:inputText id=โ€œfNameInput" value="#{UserRegistrationBean.firstName}"/> 19 JEE - Java Server Faces (JSF)
  • 20. JSF Validators โ€ข Validatorsโ€”Perform correctness checks on UIInput values โ€ข Register one or more per component โ€ข Enqueue one or more messages on errors โ€ข Standard implementations for common cases โ€ข Example <h:input_text valueRef=โ€testingBean.todayโ€ <f:validator_length minimum=โ€6โ€ maximum='10โ€ /> 20 JEE - Java Server Faces (JSF)
  • 21. JSF Converters โ€ข Convertersโ€”Plug-in for conversions: โ€ข Output: Object to String โ€ข Input: String to Object โ€ข Standard implementations for common cases โ€ข Example <h:input_text valueRef=โ€testingBean.todayโ€ convertor=โ€DateTimeโ€/> 21 JEE - Java Server Faces (JSF)
  • 22. Navigation โ€ข Application developer defines the navigation model of the web application โ€ข in Application configuration file (Facesconfig.xml) โ€ข Navigation rules โ€ข Determine where (page) to go. โ€ข Precise navigation case 22 JEE - Java Server Faces (JSF)
  • 23. JSF Development Steps 1. Build Model from Java Beans โ€ข Lifetime Configured by developer and managed by JSF โ€ข Request, Session, or Application Scope โ€ข Setters and getters accessed through JSF pages 2. Add model objects (managed bean) declarations to Application Configuration File faces-config.xml 3. Use UI Components to build JSF pages โ€ข Include JSF Tags, Validation and Event Listeners 4. Define Page Navigation rules in faces.config.xml 5. Configure web.xml 23 JEE - Java Server Faces (JSF)
  • 24. Step 1 - Build Model โ€ข The model (M) in MVC โ€ข A regular JavaBeans with getters / setters โ€ข May contain application methods and event handlers โ€ข Use to hold data from a UI (page) โ€ข Creation and lifetime is managed by JSF runtime โ€ข application, session, request โ€ข JSF keeps the bean's data in sync with the UI 24 JEE - Java Server Faces (JSF)
  • 25. Step 2 - Declare Model Objects โ€ข In Faces-config.xml <managed-bean> <managed-bean-name> LoginFormBean </managed-bean-name> <managed-bean-class> myapp.LoginFormBean </managed-bean-class> <managed-bean-scope> request </managed-bean-scope> </managed-bean> 25 JEE - Java Server Faces (JSF)
  • 26. Step 3 - Create JSF Pages โ€ข Must include JSF tag library โ€ข HTML and core tags โ€ข All JSF tags must enclosed between a set of view tag โ€ข Use JSF form and form component tags โ€ข <h:input_text> not <input type=โ€textโ€> โ€ข <h:command_button> not <input type=โ€submitโ€> โ€ข May include validators and event listeners on any form components 26 JEE - Java Server Faces (JSF)
  • 27. Step 3 - Create JSF Pages <f:view> <f:form formName=โ€logonFormโ€> <h:panel_grid columns=โ€2โ€> <h:output_text value=โ€Username:โ€/> <h:input_text id=โ€usernameโ€ length=โ€16โ€ valueRef=โ€logonBean.usernameโ€/> <h:output_text value=โ€Password:โ€/> <h:input_secret id=โ€passwordโ€ length=โ€16โ€ valueRef=โ€logonBean.passwordโ€/> <h:command_button type=โ€submitโ€ label=โ€Log Onโ€ actionRef=โ€logonBean.logonโ€/> <h:command_button type=โ€resetโ€ label=โ€Resetโ€/> </h:panel_grid> </f:form> </f:view> 27
  • 28. Step 4 - Define Navigation <navigation-rule> <from-tree-id> /login.jsp </from-tree-id> <navigation-case> <from-outcome>success</from-outcome> <to-tree-id>/menu.jsp</to-tree-id> </navigation-case> <navigation-case> <from-outcome>failed</from-outcome> <to-tree-id>/error.jsp</to-tree-id> </navigation-case> </navigation-rule> 28 JEE - Java Server Faces (JSF)
  • 29. Step 5 - Configure Web.xml <context-param> <param-name> javax.faces.application.CONFIG_FILES </param-name> <param-value>/WEB-INF/faces-config.xml </param-value> </context-param> <servlet> <servlet-name>Faces Servlet</servlet-name> <servlet-class> javax.faces.webapp.FacesServlet</servlet-class> <load-on-startup> 1 </load-on-startup> </servlet> <!-- Faces Servlet Mapping --> <servlet-mapping> <servlet-name>Faces Servlet</servlet-name> <url-pattern>/faces/*</url-pattern> </servlet-mapping> 29 JEE - Java Server Faces (JSF)
  • 30. JSF vs. JSP for UI 30 JSF JSP Components โ€ข Rich UI-data-bound components with events provided โ€ข Custom components โ€ข Standard tags (JSTL) that are non-UI and very basic โ€ข Custom components through tag libraries Device independence โ€ข Reader kits that provide device independence โ€ข None Error handling and validation โ€ข Validation framework โ€ข Many predefined validators โ€ข None Scripting โ€ข Scripts can be attached to events โ€ข All components accessible from scripts โ€ข Embedded Java in the page Page flow โ€ข Simple navigation file (faces- config.xml) โ€ข None
  • 31. 31 JEE - Java Server Faces (JSF)