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

Spring JDBCTemplate
Spring JDBCTemplateSpring JDBCTemplate
Spring JDBCTemplateGuo Albert
 
Collections and its types in C# (with examples)
Collections and its types in C# (with examples)Collections and its types in C# (with examples)
Collections and its types in C# (with examples)Aijaz Ali Abro
 
PUC SE Day 2019 - SpringBoot
PUC SE Day 2019 - SpringBootPUC SE Day 2019 - SpringBoot
PUC SE Day 2019 - SpringBootJosué Neis
 
Use Node.js to create a REST API
Use Node.js to create a REST APIUse Node.js to create a REST API
Use Node.js to create a REST APIFabien Vauchelles
 
jpa-hibernate-presentation
jpa-hibernate-presentationjpa-hibernate-presentation
jpa-hibernate-presentationJohn Slick
 
Rediscovering Spring with Spring Boot(1)
Rediscovering Spring with Spring Boot(1)Rediscovering Spring with Spring Boot(1)
Rediscovering Spring with Spring Boot(1)Gunith Devasurendra
 
Spring boot
Spring bootSpring boot
Spring bootsdeeg
 
REST APIs with Spring
REST APIs with SpringREST APIs with Spring
REST APIs with SpringJoshua Long
 
Hibernate Presentation
Hibernate  PresentationHibernate  Presentation
Hibernate Presentationguest11106b
 
Hibernate ppt
Hibernate pptHibernate ppt
Hibernate pptAneega
 
Java EE Introduction
Java EE IntroductionJava EE Introduction
Java EE Introductionejlp12
 

What's hot (20)

Angular
AngularAngular
Angular
 
Spring Boot Tutorial
Spring Boot TutorialSpring Boot Tutorial
Spring Boot Tutorial
 
An introduction to MongoDB
An introduction to MongoDBAn introduction to MongoDB
An introduction to MongoDB
 
jQuery
jQueryjQuery
jQuery
 
Spring JDBCTemplate
Spring JDBCTemplateSpring JDBCTemplate
Spring JDBCTemplate
 
Collections and its types in C# (with examples)
Collections and its types in C# (with examples)Collections and its types in C# (with examples)
Collections and its types in C# (with examples)
 
Getting started with entity framework
Getting started with entity framework Getting started with entity framework
Getting started with entity framework
 
PUC SE Day 2019 - SpringBoot
PUC SE Day 2019 - SpringBootPUC SE Day 2019 - SpringBoot
PUC SE Day 2019 - SpringBoot
 
MySQL Basics
MySQL BasicsMySQL Basics
MySQL Basics
 
Hibernate in Action
Hibernate in ActionHibernate in Action
Hibernate in Action
 
Use Node.js to create a REST API
Use Node.js to create a REST APIUse Node.js to create a REST API
Use Node.js to create a REST API
 
jpa-hibernate-presentation
jpa-hibernate-presentationjpa-hibernate-presentation
jpa-hibernate-presentation
 
Rediscovering Spring with Spring Boot(1)
Rediscovering Spring with Spring Boot(1)Rediscovering Spring with Spring Boot(1)
Rediscovering Spring with Spring Boot(1)
 
Spring boot
Spring bootSpring boot
Spring boot
 
Spring & hibernate
Spring & hibernateSpring & hibernate
Spring & hibernate
 
REST APIs with Spring
REST APIs with SpringREST APIs with Spring
REST APIs with Spring
 
Hibernate Presentation
Hibernate  PresentationHibernate  Presentation
Hibernate Presentation
 
Curso Java Avanzado 5 Ejb
Curso Java Avanzado   5 EjbCurso Java Avanzado   5 Ejb
Curso Java Avanzado 5 Ejb
 
Hibernate ppt
Hibernate pptHibernate ppt
Hibernate ppt
 
Java EE Introduction
Java EE IntroductionJava EE Introduction
Java EE Introduction
 

Similar to Lecture 10 - Java Server Faces (JSF)

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 MVCJosh Juneau
 
JSF basics
JSF basicsJSF basics
JSF basicsairbo
 
AK 5 JSF 21 july 2008
AK 5 JSF   21 july 2008AK 5 JSF   21 july 2008
AK 5 JSF 21 july 2008gauravashq
 
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 Skills Matter
 
Contextual Dependency Injection for Apachecon 2010
Contextual Dependency Injection for Apachecon 2010Contextual Dependency Injection for Apachecon 2010
Contextual Dependency Injection for Apachecon 2010Rohit Kelapure
 
Glassfish JEE Server Administration - JEE Introduction
Glassfish JEE Server Administration - JEE IntroductionGlassfish JEE Server Administration - JEE Introduction
Glassfish JEE Server Administration - JEE IntroductionDanairat Thanabodithammachari
 
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)Kevin Sutter
 
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 ApproachAnghel Leonard
 
Case Study: Migrating Hyperic from EJB to Spring from JBoss to Apache Tomcat
Case Study: Migrating Hyperic from EJB to Spring from JBoss to Apache TomcatCase Study: Migrating Hyperic from EJB to Spring from JBoss to Apache Tomcat
Case Study: Migrating Hyperic from EJB to Spring from JBoss to Apache TomcatVMware Hyperic
 

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
 
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
 
Case Study: Migrating Hyperic from EJB to Spring from JBoss to Apache Tomcat
Case Study: Migrating Hyperic from EJB to Spring from JBoss to Apache TomcatCase Study: Migrating Hyperic from EJB to Spring from JBoss to Apache Tomcat
Case Study: Migrating Hyperic from EJB to Spring from JBoss to Apache Tomcat
 

More from Fahad Golra

Seance 4- Programmation en langage C
Seance 4- Programmation en langage CSeance 4- Programmation en langage C
Seance 4- Programmation en langage CFahad 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
 
Seance 2 - Programmation en langage C
Seance 2 - Programmation en langage CSeance 2 - Programmation en langage C
Seance 2 - Programmation en langage CFahad Golra
 
Seance 1 - Programmation en langage C
Seance 1 - Programmation en langage CSeance 1 - Programmation en langage C
Seance 1 - Programmation en langage CFahad Golra
 
Tutorial 4 - Basics of Digital Photography
Tutorial 4 - Basics of Digital PhotographyTutorial 4 - Basics of Digital Photography
Tutorial 4 - Basics of Digital PhotographyFahad Golra
 
Tutorial 3 - Basics of Digital Photography
Tutorial 3 - Basics of Digital PhotographyTutorial 3 - Basics of Digital Photography
Tutorial 3 - Basics of Digital PhotographyFahad Golra
 
Tutorial 2 - Basics of Digital Photography
Tutorial 2 - Basics of Digital PhotographyTutorial 2 - Basics of Digital Photography
Tutorial 2 - Basics of Digital PhotographyFahad Golra
 
Tutorial 1 - Basics of Digital Photography
Tutorial 1 - Basics of Digital PhotographyTutorial 1 - Basics of Digital Photography
Tutorial 1 - Basics of Digital PhotographyFahad Golra
 
Lecture 9 - Java Persistence, JPA 2
Lecture 9 - Java Persistence, JPA 2Lecture 9 - Java Persistence, JPA 2
Lecture 9 - Java Persistence, JPA 2Fahad Golra
 
Lecture 8 Enterprise Java Beans (EJB)
Lecture 8  Enterprise Java Beans (EJB)Lecture 8  Enterprise Java Beans (EJB)
Lecture 8 Enterprise Java Beans (EJB)Fahad Golra
 
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-RSFahad Golra
 
Lecture 6 Web Sockets
Lecture 6   Web SocketsLecture 6   Web Sockets
Lecture 6 Web SocketsFahad Golra
 
Lecture 5 JSTL, custom tags, maven
Lecture 5   JSTL, custom tags, mavenLecture 5   JSTL, custom tags, maven
Lecture 5 JSTL, custom tags, mavenFahad Golra
 
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)Fahad Golra
 
Lecture 2: Servlets
Lecture 2:  ServletsLecture 2:  Servlets
Lecture 2: ServletsFahad Golra
 
Lecture 1: Introduction to JEE
Lecture 1:  Introduction to JEELecture 1:  Introduction to JEE
Lecture 1: Introduction to JEEFahad Golra
 
Lecture 3: Servlets - Session Management
Lecture 3:  Servlets - Session ManagementLecture 3:  Servlets - Session Management
Lecture 3: Servlets - Session ManagementFahad Golra
 
Deviation Detection in Process Enactment
Deviation Detection in Process EnactmentDeviation Detection in Process Enactment
Deviation Detection in Process EnactmentFahad Golra
 
Meta l metacase tools & possibilities
Meta l metacase tools & possibilitiesMeta l metacase tools & possibilities
Meta l metacase tools & possibilitiesFahad 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

SensoDat: Simulation-based Sensor Dataset of Self-driving Cars
SensoDat: Simulation-based Sensor Dataset of Self-driving CarsSensoDat: Simulation-based Sensor Dataset of Self-driving Cars
SensoDat: Simulation-based Sensor Dataset of Self-driving CarsChristian Birchler
 
SAM Training Session - How to use EXCEL ?
SAM Training Session - How to use EXCEL ?SAM Training Session - How to use EXCEL ?
SAM Training Session - How to use EXCEL ?Alexandre Beguel
 
SpotFlow: Tracking Method Calls and States at Runtime
SpotFlow: Tracking Method Calls and States at RuntimeSpotFlow: Tracking Method Calls and States at Runtime
SpotFlow: Tracking Method Calls and States at Runtimeandrehoraa
 
Not a Kubernetes fan? The state of PaaS in 2024
Not a Kubernetes fan? The state of PaaS in 2024Not a Kubernetes fan? The state of PaaS in 2024
Not a Kubernetes fan? The state of PaaS in 2024Anthony Dahanne
 
Salesforce Implementation Services PPT By ABSYZ
Salesforce Implementation Services PPT By ABSYZSalesforce Implementation Services PPT By ABSYZ
Salesforce Implementation Services PPT By ABSYZABSYZ Inc
 
Tech Tuesday Slides - Introduction to Project Management with OnePlan's Work ...
Tech Tuesday Slides - Introduction to Project Management with OnePlan's Work ...Tech Tuesday Slides - Introduction to Project Management with OnePlan's Work ...
Tech Tuesday Slides - Introduction to Project Management with OnePlan's Work ...OnePlan Solutions
 
Exploring Selenium_Appium Frameworks for Seamless Integration with HeadSpin.pdf
Exploring Selenium_Appium Frameworks for Seamless Integration with HeadSpin.pdfExploring Selenium_Appium Frameworks for Seamless Integration with HeadSpin.pdf
Exploring Selenium_Appium Frameworks for Seamless Integration with HeadSpin.pdfkalichargn70th171
 
Alfresco TTL#157 - Troubleshooting Made Easy: Deciphering Alfresco mTLS Confi...
Alfresco TTL#157 - Troubleshooting Made Easy: Deciphering Alfresco mTLS Confi...Alfresco TTL#157 - Troubleshooting Made Easy: Deciphering Alfresco mTLS Confi...
Alfresco TTL#157 - Troubleshooting Made Easy: Deciphering Alfresco mTLS Confi...Angel Borroy López
 
Patterns for automating API delivery. API conference
Patterns for automating API delivery. API conferencePatterns for automating API delivery. API conference
Patterns for automating API delivery. API conferencessuser9e7c64
 
Ronisha Informatics Private Limited Catalogue
Ronisha Informatics Private Limited CatalogueRonisha Informatics Private Limited Catalogue
Ronisha Informatics Private Limited Catalogueitservices996
 
UI5ers live - Custom Controls wrapping 3rd-party libs.pptx
UI5ers live - Custom Controls wrapping 3rd-party libs.pptxUI5ers live - Custom Controls wrapping 3rd-party libs.pptx
UI5ers live - Custom Controls wrapping 3rd-party libs.pptxAndreas Kunz
 
eSoftTools IMAP Backup Software and migration tools
eSoftTools IMAP Backup Software and migration toolseSoftTools IMAP Backup Software and migration tools
eSoftTools IMAP Backup Software and migration toolsosttopstonverter
 
Osi security architecture in network.pptx
Osi security architecture in network.pptxOsi security architecture in network.pptx
Osi security architecture in network.pptxVinzoCenzo
 
The Role of IoT and Sensor Technology in Cargo Cloud Solutions.pptx
The Role of IoT and Sensor Technology in Cargo Cloud Solutions.pptxThe Role of IoT and Sensor Technology in Cargo Cloud Solutions.pptx
The Role of IoT and Sensor Technology in Cargo Cloud Solutions.pptxRTS corp
 
Comparing Linux OS Image Update Models - EOSS 2024.pdf
Comparing Linux OS Image Update Models - EOSS 2024.pdfComparing Linux OS Image Update Models - EOSS 2024.pdf
Comparing Linux OS Image Update Models - EOSS 2024.pdfDrew Moseley
 
Understanding Flamingo - DeepMind's VLM Architecture
Understanding Flamingo - DeepMind's VLM ArchitectureUnderstanding Flamingo - DeepMind's VLM Architecture
Understanding Flamingo - DeepMind's VLM Architecturerahul_net
 
OpenChain Education Work Group Monthly Meeting - 2024-04-10 - Full Recording
OpenChain Education Work Group Monthly Meeting - 2024-04-10 - Full RecordingOpenChain Education Work Group Monthly Meeting - 2024-04-10 - Full Recording
OpenChain Education Work Group Monthly Meeting - 2024-04-10 - Full RecordingShane Coughlan
 
Revolutionizing the Digital Transformation Office - Leveraging OnePlan’s AI a...
Revolutionizing the Digital Transformation Office - Leveraging OnePlan’s AI a...Revolutionizing the Digital Transformation Office - Leveraging OnePlan’s AI a...
Revolutionizing the Digital Transformation Office - Leveraging OnePlan’s AI a...OnePlan Solutions
 
OpenChain AI Study Group - Europe and Asia Recap - 2024-04-11 - Full Recording
OpenChain AI Study Group - Europe and Asia Recap - 2024-04-11 - Full RecordingOpenChain AI Study Group - Europe and Asia Recap - 2024-04-11 - Full Recording
OpenChain AI Study Group - Europe and Asia Recap - 2024-04-11 - Full RecordingShane Coughlan
 
VK Business Profile - provides IT solutions and Web Development
VK Business Profile - provides IT solutions and Web DevelopmentVK Business Profile - provides IT solutions and Web Development
VK Business Profile - provides IT solutions and Web Developmentvyaparkranti
 

Recently uploaded (20)

SensoDat: Simulation-based Sensor Dataset of Self-driving Cars
SensoDat: Simulation-based Sensor Dataset of Self-driving CarsSensoDat: Simulation-based Sensor Dataset of Self-driving Cars
SensoDat: Simulation-based Sensor Dataset of Self-driving Cars
 
SAM Training Session - How to use EXCEL ?
SAM Training Session - How to use EXCEL ?SAM Training Session - How to use EXCEL ?
SAM Training Session - How to use EXCEL ?
 
SpotFlow: Tracking Method Calls and States at Runtime
SpotFlow: Tracking Method Calls and States at RuntimeSpotFlow: Tracking Method Calls and States at Runtime
SpotFlow: Tracking Method Calls and States at Runtime
 
Not a Kubernetes fan? The state of PaaS in 2024
Not a Kubernetes fan? The state of PaaS in 2024Not a Kubernetes fan? The state of PaaS in 2024
Not a Kubernetes fan? The state of PaaS in 2024
 
Salesforce Implementation Services PPT By ABSYZ
Salesforce Implementation Services PPT By ABSYZSalesforce Implementation Services PPT By ABSYZ
Salesforce Implementation Services PPT By ABSYZ
 
Tech Tuesday Slides - Introduction to Project Management with OnePlan's Work ...
Tech Tuesday Slides - Introduction to Project Management with OnePlan's Work ...Tech Tuesday Slides - Introduction to Project Management with OnePlan's Work ...
Tech Tuesday Slides - Introduction to Project Management with OnePlan's Work ...
 
Exploring Selenium_Appium Frameworks for Seamless Integration with HeadSpin.pdf
Exploring Selenium_Appium Frameworks for Seamless Integration with HeadSpin.pdfExploring Selenium_Appium Frameworks for Seamless Integration with HeadSpin.pdf
Exploring Selenium_Appium Frameworks for Seamless Integration with HeadSpin.pdf
 
Alfresco TTL#157 - Troubleshooting Made Easy: Deciphering Alfresco mTLS Confi...
Alfresco TTL#157 - Troubleshooting Made Easy: Deciphering Alfresco mTLS Confi...Alfresco TTL#157 - Troubleshooting Made Easy: Deciphering Alfresco mTLS Confi...
Alfresco TTL#157 - Troubleshooting Made Easy: Deciphering Alfresco mTLS Confi...
 
Patterns for automating API delivery. API conference
Patterns for automating API delivery. API conferencePatterns for automating API delivery. API conference
Patterns for automating API delivery. API conference
 
Ronisha Informatics Private Limited Catalogue
Ronisha Informatics Private Limited CatalogueRonisha Informatics Private Limited Catalogue
Ronisha Informatics Private Limited Catalogue
 
UI5ers live - Custom Controls wrapping 3rd-party libs.pptx
UI5ers live - Custom Controls wrapping 3rd-party libs.pptxUI5ers live - Custom Controls wrapping 3rd-party libs.pptx
UI5ers live - Custom Controls wrapping 3rd-party libs.pptx
 
eSoftTools IMAP Backup Software and migration tools
eSoftTools IMAP Backup Software and migration toolseSoftTools IMAP Backup Software and migration tools
eSoftTools IMAP Backup Software and migration tools
 
Osi security architecture in network.pptx
Osi security architecture in network.pptxOsi security architecture in network.pptx
Osi security architecture in network.pptx
 
The Role of IoT and Sensor Technology in Cargo Cloud Solutions.pptx
The Role of IoT and Sensor Technology in Cargo Cloud Solutions.pptxThe Role of IoT and Sensor Technology in Cargo Cloud Solutions.pptx
The Role of IoT and Sensor Technology in Cargo Cloud Solutions.pptx
 
Comparing Linux OS Image Update Models - EOSS 2024.pdf
Comparing Linux OS Image Update Models - EOSS 2024.pdfComparing Linux OS Image Update Models - EOSS 2024.pdf
Comparing Linux OS Image Update Models - EOSS 2024.pdf
 
Understanding Flamingo - DeepMind's VLM Architecture
Understanding Flamingo - DeepMind's VLM ArchitectureUnderstanding Flamingo - DeepMind's VLM Architecture
Understanding Flamingo - DeepMind's VLM Architecture
 
OpenChain Education Work Group Monthly Meeting - 2024-04-10 - Full Recording
OpenChain Education Work Group Monthly Meeting - 2024-04-10 - Full RecordingOpenChain Education Work Group Monthly Meeting - 2024-04-10 - Full Recording
OpenChain Education Work Group Monthly Meeting - 2024-04-10 - Full Recording
 
Revolutionizing the Digital Transformation Office - Leveraging OnePlan’s AI a...
Revolutionizing the Digital Transformation Office - Leveraging OnePlan’s AI a...Revolutionizing the Digital Transformation Office - Leveraging OnePlan’s AI a...
Revolutionizing the Digital Transformation Office - Leveraging OnePlan’s AI a...
 
OpenChain AI Study Group - Europe and Asia Recap - 2024-04-11 - Full Recording
OpenChain AI Study Group - Europe and Asia Recap - 2024-04-11 - Full RecordingOpenChain AI Study Group - Europe and Asia Recap - 2024-04-11 - Full Recording
OpenChain AI Study Group - Europe and Asia Recap - 2024-04-11 - Full Recording
 
VK Business Profile - provides IT solutions and Web Development
VK Business Profile - provides IT solutions and Web DevelopmentVK Business Profile - provides IT solutions and Web Development
VK Business Profile - provides IT solutions and Web Development
 

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)