SlideShare a Scribd company logo
1 of 30
Introduction to JSF 2
Java server faces 2.x
Yousry Ibrahim / October 26, 2015
1
Agenda
2
• JSF History and different implementations.
• JSF 2 life cycle
• JSF Parts
• Managed bean
• Facelets
• Navigation
• UI Components
• AJAX
• Converters & Validation
• What is JSF and why?
• New Features in JSF
2.2
What is JSF and why?
• A standard Java framework for building Web applications.
• It provides a component-oriented client-independent development approach to building Web user
interfaces, thus improving developer productivity and ease of use.
• It describes a standard set of architectural patterns for a web application (MVC , front controller …)
• Has many releases and now has a lot of features (Built-in Facelets, Built-in Ajax, composite
components….)
3
JSF History and different implementations
• JSR 127
 JSF 1.0 11 March 2004 ( Initial specification released )
 JSF 1.1 27 May 2004 (Bug-fix release. No specification
changes. )
• JSR 252
 JSF 1.2 11 May 2006 (Many improvements to core
systems and APIs. Coincides with Java EE 5)
 JSF 1.2 Maintenance Release 1
19 December 2006
 JSF 1.2 Maintenance Release 2
13 June 2008
 JSF 1.2 Maintenance Release 3
25 August 2008
• JSR 314
 JSF 2.0 1 July 2009 (Major release for ease
of use, enhanced functionality, and
performance. Coincides with Java EE 6 )
 JSF 2.1 16 July 2010
 JSF 2.1 Maintenance Release 2
22 November 2010
• JSR 344 (JSF 2.2)
 Started 14 April 2011
 Early Draft Review released
8 December 2011
 Proposed Final Draft 14 Mar 2013
 Final June 2013 (Introduced new concepts
like stateless views, page flow and the ability
…)
4
JSF History and different implementations Con
• There are many implementations for example (ADF by oracle, My faces by apache, IBM and RI).
• The RI (reference implementation called Mojarra project )
• Each implementation can use the default Components or can Create other UI components for example:
– ADF uses rich client faces.
– My Faces can uses (Trinidad, Tobago, Tomahawk)
– Primefaces ( widely used nowadays which is not an implementations BUT set of UI components that use the RI
implementation) as well as ice faces
5
JSF 2 life cycle
6
JSF 2 life cycle Con
7
1. Restore view :
– This phase is used for constructing view to display in the front end.
– Every view has it's own view id and it is stored in the Faces Context's session object.
– JSF View is collection of components associated with its current state.
– There is two types of state saving mechanism
– Server (default)
– Client
JSF 2 life cycle Con
8
2. Apply Request Values:
– After the component tree is restored, each component in the tree extracts its new value from
the request parameters by using its decode method.
– The value is then stored locally on the component.
– If the conversion of the value fails, an error message associated with the component is
generated and queued on FacesContext.
This message will be displayed during the Render phase, along with any validation errors
resulting from the process validations phase.
JSF 2 life cycle Con
9
3. Process Validations:
– processes all validators registered on the components in the tree.
– examines the component attributes that specify the rules for the validation and compares these rules to the local value stored for the
component.
4. Update Model Values:
- After the JavaServer Faces implementation determines that the data is valid, it can walk the component tree
and set the corresponding server-side object properties to the components' local values.
- The JavaServer Faces implementation will update only the bean properties pointed at by an input component's value attribute.
- If the local data cannot be converted to the types specified by the bean properties, the life cycle advances directly to the Render phase
so that the page is re-rendered with errors displayed. (This is similar to what happens with validation errors)
JSF 2 life cycle Con
10
5. Invoke Application:
– Invokes any application logic needed to fulfill the request and navigate to a new page if needed.
– For example : after performing our business we can see the action property of the button, the action value will
redirect to another JSF view, So at this phase fetch the view and go to render phase
– If the target is not JSF view for example any URL, this phase call FacesContext.responseComplete.
6. Render Response :
– JSF have Render Kit to render the view to generate appropriate format. for example HTML render kit generate html
code from view. Render kit knows how to render the UI components.
Managed Bean
JSF Parts
• Is a Java bean that can be accessed from JSF page.
• The managed bean can be a normal Java bean, which contains the getter and setter methods, business logic
or even a backing bean (a bean contains all the HTML form value).
• How to Configure the Managed Bean in JSF 2 ?
Two Ways
– Configure Managed Bean with Annotation - Configure Managed Bean with
XML
11
Managed Bean II
JSF Parts Con.
• How to Inject the Managed Bean in JSF 2 ?
@ManagedProperty
12
Managed Bean III
JSF Parts Con.
• JSF 2 Managed Bean Scopes:
– Application, Session and Request.
– View Scope (request –  -session):
• a bean in this scope lives as long as you're interacting with the same JSF view in the browser window/tab.
• It get created upon a HTTP request and get destroyed once you postback to a different view.
• JSF stores the bean in the UIViewRoot#getViewMap() with the managed bean name as key, which is in turn stored in the session.
• Use this scope for more complex forms which use ajax, data tables and/or several rendered/disabled attributes whose state needs to be retained in the
subsequent requests within the same browser window/tab (view).
– None Scope (created once request):
• A bean in this scope lives as long as a single EL evaluation.
• It get created upon an EL evaluation and get destroyed immediately after the EL evaluation.
• JSF does not store the bean anywhere.
• So if you have for example three #{bean.someProperty} expressions in your view, then the bean get effectively created three times.
– Custom scope:
• In this scope you have to create your own map in a broader scope and you are the responsible for destroying the beans in that map.
13
Facelets
JSF Parts Con.
• invented as a JSF extension by Expert Group member Jacob Hookom, and now incorporated into the core
JSF specification in JSF 2.0.
• Facelets was created to replace the use of JSP as a View Declaration Language (Templating) for JSF.
• Its looks like Apache Tiles framework for who knows it. 
• Most used facelets tags:
– ui:insert – Used in template file, it defines content that is going to replace by the file that load the template. The content can
be replace with “ui:define” tag.
– ui:define – Defines content that is inserted into template with a matching “ui:insert” tag.
– ui:include – Similar to JSP’s “jsp:include”, includes content from another XHTML page.
– ui:composition – If used with “template” attribute, the specified template is loaded, and the children of this tag defines the
template layout; Otherwise, it’s a group of elements, that can be inserted somewhere.
14
Facelets II
JSF Parts Con.
• Example :
1- Create common header for our JSF pages as below : 2- create common footer for our JSF pages as below :
Note: all tags out of Composition will be ignored by JSF
15
Facelets III
JSF Parts Con.
3- Create default content which used in case the content tag not overridden as below : 4- then we have to create the Layout page witch
combine all
16
Facelets IV
JSF Parts Con.
5- If we use the layout with out overridden any tag as below : 6- the result will be like this
17
Facelets V
JSF Parts Con.
7- If we use the layout as below : 4- the result will be like this
18
Navigation
JSF Parts Con.
• How can we go from page to another page ?
– we can do it more than one way :
1- Configuration Navigation
19
Navigation II
JSF Parts Con.
• How can we go from page to another page ?
2- Implicit Navigation
Once the button is clicked, JSF will merge the action value or outcome, “page2” with “xhtml” extension, and find the view name “page2.xhtml” in
the current “page1.xhtml” directory.
– Redirection (show correct name in the URL)
• By default, JSF 2 is perform a forward while navigating to another page, it caused the page URL is always one behind :). For example, when you
move from “page1.xhtml” to “page2.xhtml”, the browser URL address bar will still showing the same “page1.xhtml” URL.
• To avoid this, you can tell JSF to use the redirection by append the “faces-redirect=true” to the end of the “outcome” string.
20
Components
JSF Parts Con.
21
Components II
JSF Parts Con.
22
• Some Examples of UI Components:
– h:outputText and h:inputText:
Components III
JSF Parts Con.
23
• Some Examples of UI Components:
– h:selectOneMenu
There are many components Over JSF
(Show demo Primefaces)
Ajax
JSF Parts Con.
24
• Ajax in JSF2 become built-in
– Example
Converters & Validation
JSF Parts Con.
25
• Standard Convertors and validator tags in JSF 2.0
– f:convertNumber
– f:convertDateTime
– f:validateLength
– f:validateLongRange
– f:validateRequired
– f:validateRegex
– custom validator
– custom converter
• Lets Take Some examples
Converters & Validation II
JSF Parts Con.
26
• Lets Take Some examples
• How to customize the Messages ?
– Create a properties file named “MyMessage.properties for example” (can be any name you like) as below.
Converters & Validation III
JSF Parts Con.
27
• How to customize the Messages ?
– Create a properties file named “MyMessage.properties for example” (can be any name you like) as below.
– Register Message Bundle in faces-config.xml file
New Features in JSF 2.2
28
• Faces Flows (something like ADF task flow)
This feature gives the developer the ability to develop flows that can be packaged in a JAR file and then be
distributed in any application that wishes to use it.
• HTML5 support (write HTML not JSF component)
New Features in JSF 2.2 Con.
29
• File Upload Component
This feature makes it possible to upload a file from a JSF page.
• Stateless JSF
This feature allows you to mark a Facelets page as being stateless, which means no view state is saved for the
page.
Increasing the performance just if you don’t want the state
Thank you
Yousry.Ibrahim@hpe.com
30

More Related Content

What's hot

Sun JSF Presentation
Sun JSF PresentationSun JSF Presentation
Sun JSF PresentationGaurav Dighe
 
9. java server faces
9. java server faces9. java server faces
9. java server facesAnusAhmad
 
JSF Component Behaviors
JSF Component BehaviorsJSF Component Behaviors
JSF Component BehaviorsAndy Schwartz
 
Struts Introduction Course
Struts Introduction CourseStruts Introduction Course
Struts Introduction Courseguest764934
 
Java Server Faces (JSF) - Basics
Java Server Faces (JSF) - BasicsJava Server Faces (JSF) - Basics
Java Server Faces (JSF) - BasicsBG Java EE Course
 
Java Server Faces + Spring MVC Framework
Java Server Faces + Spring MVC FrameworkJava Server Faces + Spring MVC Framework
Java Server Faces + Spring MVC FrameworkGuo Albert
 
Spring Portlet MVC
Spring Portlet MVCSpring Portlet MVC
Spring Portlet MVCJohn Lewis
 
Spring MVC
Spring MVCSpring MVC
Spring MVCyuvalb
 
Java Web Programming [7/9] : Struts2 Basics
Java Web Programming [7/9] : Struts2 BasicsJava Web Programming [7/9] : Struts2 Basics
Java Web Programming [7/9] : Struts2 BasicsIMC Institute
 
Java Web Programming [6/9] : MVC
Java Web Programming [6/9] : MVCJava Web Programming [6/9] : MVC
Java Web Programming [6/9] : MVCIMC Institute
 
JSF 2 and beyond: Keeping progress coming
JSF 2 and beyond: Keeping progress comingJSF 2 and beyond: Keeping progress coming
JSF 2 and beyond: Keeping progress comingAndy Schwartz
 
Component Framework Primer for JSF Users
Component Framework Primer for JSF UsersComponent Framework Primer for JSF Users
Component Framework Primer for JSF UsersAndy Schwartz
 
JSF 2.3: Integration with Front-End Frameworks
JSF 2.3: Integration with Front-End FrameworksJSF 2.3: Integration with Front-End Frameworks
JSF 2.3: Integration with Front-End FrameworksIan Hlavats
 
Annotation-Based Spring Portlet MVC
Annotation-Based Spring Portlet MVCAnnotation-Based Spring Portlet MVC
Annotation-Based Spring Portlet MVCJohn Lewis
 

What's hot (20)

Sun JSF Presentation
Sun JSF PresentationSun JSF Presentation
Sun JSF Presentation
 
Jsf2.0 -4
Jsf2.0 -4Jsf2.0 -4
Jsf2.0 -4
 
9. java server faces
9. java server faces9. java server faces
9. java server faces
 
Jsf Framework
Jsf FrameworkJsf Framework
Jsf Framework
 
Jsf
JsfJsf
Jsf
 
JSF Component Behaviors
JSF Component BehaviorsJSF Component Behaviors
JSF Component Behaviors
 
Struts Introduction Course
Struts Introduction CourseStruts Introduction Course
Struts Introduction Course
 
Java Server Faces (JSF) - Basics
Java Server Faces (JSF) - BasicsJava Server Faces (JSF) - Basics
Java Server Faces (JSF) - Basics
 
Java Server Faces + Spring MVC Framework
Java Server Faces + Spring MVC FrameworkJava Server Faces + Spring MVC Framework
Java Server Faces + Spring MVC Framework
 
Spring Portlet MVC
Spring Portlet MVCSpring Portlet MVC
Spring Portlet MVC
 
Spring MVC
Spring MVCSpring MVC
Spring MVC
 
Java Web Programming [7/9] : Struts2 Basics
Java Web Programming [7/9] : Struts2 BasicsJava Web Programming [7/9] : Struts2 Basics
Java Web Programming [7/9] : Struts2 Basics
 
Spring Web MVC
Spring Web MVCSpring Web MVC
Spring Web MVC
 
Java Web Programming [6/9] : MVC
Java Web Programming [6/9] : MVCJava Web Programming [6/9] : MVC
Java Web Programming [6/9] : MVC
 
JSF 2 and beyond: Keeping progress coming
JSF 2 and beyond: Keeping progress comingJSF 2 and beyond: Keeping progress coming
JSF 2 and beyond: Keeping progress coming
 
Component Framework Primer for JSF Users
Component Framework Primer for JSF UsersComponent Framework Primer for JSF Users
Component Framework Primer for JSF Users
 
JSF 2.3: Integration with Front-End Frameworks
JSF 2.3: Integration with Front-End FrameworksJSF 2.3: Integration with Front-End Frameworks
JSF 2.3: Integration with Front-End Frameworks
 
Annotation-Based Spring Portlet MVC
Annotation-Based Spring Portlet MVCAnnotation-Based Spring Portlet MVC
Annotation-Based Spring Portlet MVC
 
Jsf
JsfJsf
Jsf
 
Struts course material
Struts course materialStruts course material
Struts course material
 

Viewers also liked (7)

JSF 2.2
JSF 2.2JSF 2.2
JSF 2.2
 
Rich faces
Rich facesRich faces
Rich faces
 
Java Server Faces (JSF) - advanced
Java Server Faces (JSF) - advancedJava Server Faces (JSF) - advanced
Java Server Faces (JSF) - advanced
 
Web Applications and Deployment
Web Applications and DeploymentWeb Applications and Deployment
Web Applications and Deployment
 
Java Server Pages
Java Server PagesJava Server Pages
Java Server Pages
 
Java Server Faces 2
Java Server Faces 2Java Server Faces 2
Java Server Faces 2
 
JSF2 par la pratique
JSF2 par la pratiqueJSF2 par la pratique
JSF2 par la pratique
 

Similar to Introduction to jsf 2

AK 5 JSF 21 july 2008
AK 5 JSF   21 july 2008AK 5 JSF   21 july 2008
AK 5 JSF 21 july 2008gauravashq
 
Introduction to jsf2
Introduction to jsf2Introduction to jsf2
Introduction to jsf2Rajiv Gupta
 
JSF2 Composite Components - Ian Hlavats
JSF2 Composite Components - Ian HlavatsJSF2 Composite Components - Ian Hlavats
JSF2 Composite Components - Ian Hlavatsjaxconf
 
Drupal features knowledge sharing
Drupal features   knowledge sharingDrupal features   knowledge sharing
Drupal features knowledge sharingBrahampal Singh
 
Introduction to ejb and struts framework
Introduction to ejb and struts frameworkIntroduction to ejb and struts framework
Introduction to ejb and struts frameworks4al_com
 
Development of web apps based on JSF (TU Vienna)
Development of web apps based on JSF (TU Vienna)Development of web apps based on JSF (TU Vienna)
Development of web apps based on JSF (TU Vienna)blahap
 
Comparing Angular and React JS for SPAs
Comparing Angular and React JS for SPAsComparing Angular and React JS for SPAs
Comparing Angular and React JS for SPAsJennifer Estrada
 
Introduction to j2 ee frameworks
Introduction to j2 ee frameworksIntroduction to j2 ee frameworks
Introduction to j2 ee frameworksMukesh Kumar
 
JSF Exam Objectives
JSF Exam ObjectivesJSF Exam Objectives
JSF Exam Objectivesanandepl
 
Presentation on "An Introduction to ReactJS"
Presentation on "An Introduction to ReactJS"Presentation on "An Introduction to ReactJS"
Presentation on "An Introduction to ReactJS"Flipkart
 
Contextual Dependency Injection for Apachecon 2010
Contextual Dependency Injection for Apachecon 2010Contextual Dependency Injection for Apachecon 2010
Contextual Dependency Injection for Apachecon 2010Rohit Kelapure
 
Java EE 6 & GlassFish = Less Code + More Power at CEJUG
Java EE 6 & GlassFish = Less Code + More Power at CEJUGJava EE 6 & GlassFish = Less Code + More Power at CEJUG
Java EE 6 & GlassFish = Less Code + More Power at CEJUGArun Gupta
 
JSP Components and Directives.pdf
JSP Components and Directives.pdfJSP Components and Directives.pdf
JSP Components and Directives.pdfArumugam90
 

Similar to Introduction to jsf 2 (20)

jsf2 Notes
jsf2 Notesjsf2 Notes
jsf2 Notes
 
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
 
Introduction to jsf2
Introduction to jsf2Introduction to jsf2
Introduction to jsf2
 
JSF2 Composite Components - Ian Hlavats
JSF2 Composite Components - Ian HlavatsJSF2 Composite Components - Ian Hlavats
JSF2 Composite Components - Ian Hlavats
 
JSF2 and JSP
JSF2 and JSPJSF2 and JSP
JSF2 and JSP
 
Drupal features knowledge sharing
Drupal features   knowledge sharingDrupal features   knowledge sharing
Drupal features knowledge sharing
 
Introduction to ejb and struts framework
Introduction to ejb and struts frameworkIntroduction to ejb and struts framework
Introduction to ejb and struts framework
 
NLOUG 2018 - Future of JSF and ADF
NLOUG 2018 - Future of JSF and ADFNLOUG 2018 - Future of JSF and ADF
NLOUG 2018 - Future of JSF and ADF
 
Development of web apps based on JSF (TU Vienna)
Development of web apps based on JSF (TU Vienna)Development of web apps based on JSF (TU Vienna)
Development of web apps based on JSF (TU Vienna)
 
Fame
FameFame
Fame
 
Comparing Angular and React JS for SPAs
Comparing Angular and React JS for SPAsComparing Angular and React JS for SPAs
Comparing Angular and React JS for SPAs
 
Introduction to j2 ee frameworks
Introduction to j2 ee frameworksIntroduction to j2 ee frameworks
Introduction to j2 ee frameworks
 
JSF Exam Objectives
JSF Exam ObjectivesJSF Exam Objectives
JSF Exam Objectives
 
Presentation on "An Introduction to ReactJS"
Presentation on "An Introduction to ReactJS"Presentation on "An Introduction to ReactJS"
Presentation on "An Introduction to ReactJS"
 
Contextual Dependency Injection for Apachecon 2010
Contextual Dependency Injection for Apachecon 2010Contextual Dependency Injection for Apachecon 2010
Contextual Dependency Injection for Apachecon 2010
 
Java EE 6 & GlassFish = Less Code + More Power at CEJUG
Java EE 6 & GlassFish = Less Code + More Power at CEJUGJava EE 6 & GlassFish = Less Code + More Power at CEJUG
Java EE 6 & GlassFish = Less Code + More Power at CEJUG
 
JSP Components and Directives.pdf
JSP Components and Directives.pdfJSP Components and Directives.pdf
JSP Components and Directives.pdf
 
Jsf 2
Jsf 2Jsf 2
Jsf 2
 
Jsf 2.0 Overview
Jsf 2.0 OverviewJsf 2.0 Overview
Jsf 2.0 Overview
 

Recently uploaded

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...kellynguyen01
 
Salesforce Certified Field Service Consultant
Salesforce Certified Field Service ConsultantSalesforce Certified Field Service Consultant
Salesforce Certified Field Service ConsultantAxelRicardoTrocheRiq
 
The Essentials of Digital Experience Monitoring_ A Comprehensive Guide.pdf
The Essentials of Digital Experience Monitoring_ A Comprehensive Guide.pdfThe Essentials of Digital Experience Monitoring_ A Comprehensive Guide.pdf
The Essentials of Digital Experience Monitoring_ A Comprehensive Guide.pdfkalichargn70th171
 
Professional Resume Template for Software Developers
Professional Resume Template for Software DevelopersProfessional Resume Template for Software Developers
Professional Resume Template for Software DevelopersVinodh Ram
 
why an Opensea Clone Script might be your perfect match.pdf
why an Opensea Clone Script might be your perfect match.pdfwhy an Opensea Clone Script might be your perfect match.pdf
why an Opensea Clone Script might be your perfect match.pdfjoe51371421
 
Adobe Marketo Engage Deep Dives: Using Webhooks to Transfer Data
Adobe Marketo Engage Deep Dives: Using Webhooks to Transfer DataAdobe Marketo Engage Deep Dives: Using Webhooks to Transfer Data
Adobe Marketo Engage Deep Dives: Using Webhooks to Transfer DataBradBedford3
 
EY_Graph Database Powered Sustainability
EY_Graph Database Powered SustainabilityEY_Graph Database Powered Sustainability
EY_Graph Database Powered SustainabilityNeo4j
 
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 CCTVshikhaohhpro
 
Russian Call Girls in Karol Bagh Aasnvi ➡️ 8264348440 💋📞 Independent Escort S...
Russian Call Girls in Karol Bagh Aasnvi ➡️ 8264348440 💋📞 Independent Escort S...Russian Call Girls in Karol Bagh Aasnvi ➡️ 8264348440 💋📞 Independent Escort S...
Russian Call Girls in Karol Bagh Aasnvi ➡️ 8264348440 💋📞 Independent Escort S...soniya singh
 
Building Real-Time Data Pipelines: Stream & Batch Processing workshop Slide
Building Real-Time Data Pipelines: Stream & Batch Processing workshop SlideBuilding Real-Time Data Pipelines: Stream & Batch Processing workshop Slide
Building Real-Time Data Pipelines: Stream & Batch Processing workshop SlideChristina Lin
 
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 ...MyIntelliSource, Inc.
 
BATTLEFIELD ORM: TIPS, TACTICS AND STRATEGIES FOR CONQUERING YOUR DATABASE
BATTLEFIELD ORM: TIPS, TACTICS AND STRATEGIES FOR CONQUERING YOUR DATABASEBATTLEFIELD ORM: TIPS, TACTICS AND STRATEGIES FOR CONQUERING YOUR DATABASE
BATTLEFIELD ORM: TIPS, TACTICS AND STRATEGIES FOR CONQUERING YOUR DATABASEOrtus Solutions, Corp
 
Call Girls in Naraina Delhi 💯Call Us 🔝8264348440🔝
Call Girls in Naraina Delhi 💯Call Us 🔝8264348440🔝Call Girls in Naraina Delhi 💯Call Us 🔝8264348440🔝
Call Girls in Naraina Delhi 💯Call Us 🔝8264348440🔝soniya singh
 
Learn the Fundamentals of XCUITest Framework_ A Beginner's Guide.pdf
Learn the Fundamentals of XCUITest Framework_ A Beginner's Guide.pdfLearn the Fundamentals of XCUITest Framework_ A Beginner's Guide.pdf
Learn the Fundamentals of XCUITest Framework_ A Beginner's Guide.pdfkalichargn70th171
 
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...ICS
 
Advancing Engineering with AI through the Next Generation of Strategic Projec...
Advancing Engineering with AI through the Next Generation of Strategic Projec...Advancing Engineering with AI through the Next Generation of Strategic Projec...
Advancing Engineering with AI through the Next Generation of Strategic Projec...OnePlan Solutions
 
Engage Usergroup 2024 - The Good The Bad_The Ugly
Engage Usergroup 2024 - The Good The Bad_The UglyEngage Usergroup 2024 - The Good The Bad_The Ugly
Engage Usergroup 2024 - The Good The Bad_The UglyFrank van der Linden
 
HR Software Buyers Guide in 2024 - HRSoftware.com
HR Software Buyers Guide in 2024 - HRSoftware.comHR Software Buyers Guide in 2024 - HRSoftware.com
HR Software Buyers Guide in 2024 - HRSoftware.comFatema Valibhai
 
Project Based Learning (A.I).pptx detail explanation
Project Based Learning (A.I).pptx detail explanationProject Based Learning (A.I).pptx detail explanation
Project Based Learning (A.I).pptx detail explanationkaushalgiri8080
 
(Genuine) Escort Service Lucknow | Starting ₹,5K To @25k with A/C 🧑🏽‍❤️‍🧑🏻 89...
(Genuine) Escort Service Lucknow | Starting ₹,5K To @25k with A/C 🧑🏽‍❤️‍🧑🏻 89...(Genuine) Escort Service Lucknow | Starting ₹,5K To @25k with A/C 🧑🏽‍❤️‍🧑🏻 89...
(Genuine) Escort Service Lucknow | Starting ₹,5K To @25k with A/C 🧑🏽‍❤️‍🧑🏻 89...gurkirankumar98700
 

Recently uploaded (20)

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...
 
Salesforce Certified Field Service Consultant
Salesforce Certified Field Service ConsultantSalesforce Certified Field Service Consultant
Salesforce Certified Field Service Consultant
 
The Essentials of Digital Experience Monitoring_ A Comprehensive Guide.pdf
The Essentials of Digital Experience Monitoring_ A Comprehensive Guide.pdfThe Essentials of Digital Experience Monitoring_ A Comprehensive Guide.pdf
The Essentials of Digital Experience Monitoring_ A Comprehensive Guide.pdf
 
Professional Resume Template for Software Developers
Professional Resume Template for Software DevelopersProfessional Resume Template for Software Developers
Professional Resume Template for Software Developers
 
why an Opensea Clone Script might be your perfect match.pdf
why an Opensea Clone Script might be your perfect match.pdfwhy an Opensea Clone Script might be your perfect match.pdf
why an Opensea Clone Script might be your perfect match.pdf
 
Adobe Marketo Engage Deep Dives: Using Webhooks to Transfer Data
Adobe Marketo Engage Deep Dives: Using Webhooks to Transfer DataAdobe Marketo Engage Deep Dives: Using Webhooks to Transfer Data
Adobe Marketo Engage Deep Dives: Using Webhooks to Transfer Data
 
EY_Graph Database Powered Sustainability
EY_Graph Database Powered SustainabilityEY_Graph Database Powered Sustainability
EY_Graph Database Powered Sustainability
 
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
 
Russian Call Girls in Karol Bagh Aasnvi ➡️ 8264348440 💋📞 Independent Escort S...
Russian Call Girls in Karol Bagh Aasnvi ➡️ 8264348440 💋📞 Independent Escort S...Russian Call Girls in Karol Bagh Aasnvi ➡️ 8264348440 💋📞 Independent Escort S...
Russian Call Girls in Karol Bagh Aasnvi ➡️ 8264348440 💋📞 Independent Escort S...
 
Building Real-Time Data Pipelines: Stream & Batch Processing workshop Slide
Building Real-Time Data Pipelines: Stream & Batch Processing workshop SlideBuilding Real-Time Data Pipelines: Stream & Batch Processing workshop Slide
Building Real-Time Data Pipelines: Stream & Batch Processing workshop Slide
 
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 ...
 
BATTLEFIELD ORM: TIPS, TACTICS AND STRATEGIES FOR CONQUERING YOUR DATABASE
BATTLEFIELD ORM: TIPS, TACTICS AND STRATEGIES FOR CONQUERING YOUR DATABASEBATTLEFIELD ORM: TIPS, TACTICS AND STRATEGIES FOR CONQUERING YOUR DATABASE
BATTLEFIELD ORM: TIPS, TACTICS AND STRATEGIES FOR CONQUERING YOUR DATABASE
 
Call Girls in Naraina Delhi 💯Call Us 🔝8264348440🔝
Call Girls in Naraina Delhi 💯Call Us 🔝8264348440🔝Call Girls in Naraina Delhi 💯Call Us 🔝8264348440🔝
Call Girls in Naraina Delhi 💯Call Us 🔝8264348440🔝
 
Learn the Fundamentals of XCUITest Framework_ A Beginner's Guide.pdf
Learn the Fundamentals of XCUITest Framework_ A Beginner's Guide.pdfLearn the Fundamentals of XCUITest Framework_ A Beginner's Guide.pdf
Learn the Fundamentals of XCUITest Framework_ A Beginner's Guide.pdf
 
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...
 
Advancing Engineering with AI through the Next Generation of Strategic Projec...
Advancing Engineering with AI through the Next Generation of Strategic Projec...Advancing Engineering with AI through the Next Generation of Strategic Projec...
Advancing Engineering with AI through the Next Generation of Strategic Projec...
 
Engage Usergroup 2024 - The Good The Bad_The Ugly
Engage Usergroup 2024 - The Good The Bad_The UglyEngage Usergroup 2024 - The Good The Bad_The Ugly
Engage Usergroup 2024 - The Good The Bad_The Ugly
 
HR Software Buyers Guide in 2024 - HRSoftware.com
HR Software Buyers Guide in 2024 - HRSoftware.comHR Software Buyers Guide in 2024 - HRSoftware.com
HR Software Buyers Guide in 2024 - HRSoftware.com
 
Project Based Learning (A.I).pptx detail explanation
Project Based Learning (A.I).pptx detail explanationProject Based Learning (A.I).pptx detail explanation
Project Based Learning (A.I).pptx detail explanation
 
(Genuine) Escort Service Lucknow | Starting ₹,5K To @25k with A/C 🧑🏽‍❤️‍🧑🏻 89...
(Genuine) Escort Service Lucknow | Starting ₹,5K To @25k with A/C 🧑🏽‍❤️‍🧑🏻 89...(Genuine) Escort Service Lucknow | Starting ₹,5K To @25k with A/C 🧑🏽‍❤️‍🧑🏻 89...
(Genuine) Escort Service Lucknow | Starting ₹,5K To @25k with A/C 🧑🏽‍❤️‍🧑🏻 89...
 

Introduction to jsf 2

  • 1. Introduction to JSF 2 Java server faces 2.x Yousry Ibrahim / October 26, 2015 1
  • 2. Agenda 2 • JSF History and different implementations. • JSF 2 life cycle • JSF Parts • Managed bean • Facelets • Navigation • UI Components • AJAX • Converters & Validation • What is JSF and why? • New Features in JSF 2.2
  • 3. What is JSF and why? • A standard Java framework for building Web applications. • It provides a component-oriented client-independent development approach to building Web user interfaces, thus improving developer productivity and ease of use. • It describes a standard set of architectural patterns for a web application (MVC , front controller …) • Has many releases and now has a lot of features (Built-in Facelets, Built-in Ajax, composite components….) 3
  • 4. JSF History and different implementations • JSR 127  JSF 1.0 11 March 2004 ( Initial specification released )  JSF 1.1 27 May 2004 (Bug-fix release. No specification changes. ) • JSR 252  JSF 1.2 11 May 2006 (Many improvements to core systems and APIs. Coincides with Java EE 5)  JSF 1.2 Maintenance Release 1 19 December 2006  JSF 1.2 Maintenance Release 2 13 June 2008  JSF 1.2 Maintenance Release 3 25 August 2008 • JSR 314  JSF 2.0 1 July 2009 (Major release for ease of use, enhanced functionality, and performance. Coincides with Java EE 6 )  JSF 2.1 16 July 2010  JSF 2.1 Maintenance Release 2 22 November 2010 • JSR 344 (JSF 2.2)  Started 14 April 2011  Early Draft Review released 8 December 2011  Proposed Final Draft 14 Mar 2013  Final June 2013 (Introduced new concepts like stateless views, page flow and the ability …) 4
  • 5. JSF History and different implementations Con • There are many implementations for example (ADF by oracle, My faces by apache, IBM and RI). • The RI (reference implementation called Mojarra project ) • Each implementation can use the default Components or can Create other UI components for example: – ADF uses rich client faces. – My Faces can uses (Trinidad, Tobago, Tomahawk) – Primefaces ( widely used nowadays which is not an implementations BUT set of UI components that use the RI implementation) as well as ice faces 5
  • 6. JSF 2 life cycle 6
  • 7. JSF 2 life cycle Con 7 1. Restore view : – This phase is used for constructing view to display in the front end. – Every view has it's own view id and it is stored in the Faces Context's session object. – JSF View is collection of components associated with its current state. – There is two types of state saving mechanism – Server (default) – Client
  • 8. JSF 2 life cycle Con 8 2. Apply Request Values: – After the component tree is restored, each component in the tree extracts its new value from the request parameters by using its decode method. – The value is then stored locally on the component. – If the conversion of the value fails, an error message associated with the component is generated and queued on FacesContext. This message will be displayed during the Render phase, along with any validation errors resulting from the process validations phase.
  • 9. JSF 2 life cycle Con 9 3. Process Validations: – processes all validators registered on the components in the tree. – examines the component attributes that specify the rules for the validation and compares these rules to the local value stored for the component. 4. Update Model Values: - After the JavaServer Faces implementation determines that the data is valid, it can walk the component tree and set the corresponding server-side object properties to the components' local values. - The JavaServer Faces implementation will update only the bean properties pointed at by an input component's value attribute. - If the local data cannot be converted to the types specified by the bean properties, the life cycle advances directly to the Render phase so that the page is re-rendered with errors displayed. (This is similar to what happens with validation errors)
  • 10. JSF 2 life cycle Con 10 5. Invoke Application: – Invokes any application logic needed to fulfill the request and navigate to a new page if needed. – For example : after performing our business we can see the action property of the button, the action value will redirect to another JSF view, So at this phase fetch the view and go to render phase – If the target is not JSF view for example any URL, this phase call FacesContext.responseComplete. 6. Render Response : – JSF have Render Kit to render the view to generate appropriate format. for example HTML render kit generate html code from view. Render kit knows how to render the UI components.
  • 11. Managed Bean JSF Parts • Is a Java bean that can be accessed from JSF page. • The managed bean can be a normal Java bean, which contains the getter and setter methods, business logic or even a backing bean (a bean contains all the HTML form value). • How to Configure the Managed Bean in JSF 2 ? Two Ways – Configure Managed Bean with Annotation - Configure Managed Bean with XML 11
  • 12. Managed Bean II JSF Parts Con. • How to Inject the Managed Bean in JSF 2 ? @ManagedProperty 12
  • 13. Managed Bean III JSF Parts Con. • JSF 2 Managed Bean Scopes: – Application, Session and Request. – View Scope (request –  -session): • a bean in this scope lives as long as you're interacting with the same JSF view in the browser window/tab. • It get created upon a HTTP request and get destroyed once you postback to a different view. • JSF stores the bean in the UIViewRoot#getViewMap() with the managed bean name as key, which is in turn stored in the session. • Use this scope for more complex forms which use ajax, data tables and/or several rendered/disabled attributes whose state needs to be retained in the subsequent requests within the same browser window/tab (view). – None Scope (created once request): • A bean in this scope lives as long as a single EL evaluation. • It get created upon an EL evaluation and get destroyed immediately after the EL evaluation. • JSF does not store the bean anywhere. • So if you have for example three #{bean.someProperty} expressions in your view, then the bean get effectively created three times. – Custom scope: • In this scope you have to create your own map in a broader scope and you are the responsible for destroying the beans in that map. 13
  • 14. Facelets JSF Parts Con. • invented as a JSF extension by Expert Group member Jacob Hookom, and now incorporated into the core JSF specification in JSF 2.0. • Facelets was created to replace the use of JSP as a View Declaration Language (Templating) for JSF. • Its looks like Apache Tiles framework for who knows it.  • Most used facelets tags: – ui:insert – Used in template file, it defines content that is going to replace by the file that load the template. The content can be replace with “ui:define” tag. – ui:define – Defines content that is inserted into template with a matching “ui:insert” tag. – ui:include – Similar to JSP’s “jsp:include”, includes content from another XHTML page. – ui:composition – If used with “template” attribute, the specified template is loaded, and the children of this tag defines the template layout; Otherwise, it’s a group of elements, that can be inserted somewhere. 14
  • 15. Facelets II JSF Parts Con. • Example : 1- Create common header for our JSF pages as below : 2- create common footer for our JSF pages as below : Note: all tags out of Composition will be ignored by JSF 15
  • 16. Facelets III JSF Parts Con. 3- Create default content which used in case the content tag not overridden as below : 4- then we have to create the Layout page witch combine all 16
  • 17. Facelets IV JSF Parts Con. 5- If we use the layout with out overridden any tag as below : 6- the result will be like this 17
  • 18. Facelets V JSF Parts Con. 7- If we use the layout as below : 4- the result will be like this 18
  • 19. Navigation JSF Parts Con. • How can we go from page to another page ? – we can do it more than one way : 1- Configuration Navigation 19
  • 20. Navigation II JSF Parts Con. • How can we go from page to another page ? 2- Implicit Navigation Once the button is clicked, JSF will merge the action value or outcome, “page2” with “xhtml” extension, and find the view name “page2.xhtml” in the current “page1.xhtml” directory. – Redirection (show correct name in the URL) • By default, JSF 2 is perform a forward while navigating to another page, it caused the page URL is always one behind :). For example, when you move from “page1.xhtml” to “page2.xhtml”, the browser URL address bar will still showing the same “page1.xhtml” URL. • To avoid this, you can tell JSF to use the redirection by append the “faces-redirect=true” to the end of the “outcome” string. 20
  • 22. Components II JSF Parts Con. 22 • Some Examples of UI Components: – h:outputText and h:inputText:
  • 23. Components III JSF Parts Con. 23 • Some Examples of UI Components: – h:selectOneMenu There are many components Over JSF (Show demo Primefaces)
  • 24. Ajax JSF Parts Con. 24 • Ajax in JSF2 become built-in – Example
  • 25. Converters & Validation JSF Parts Con. 25 • Standard Convertors and validator tags in JSF 2.0 – f:convertNumber – f:convertDateTime – f:validateLength – f:validateLongRange – f:validateRequired – f:validateRegex – custom validator – custom converter • Lets Take Some examples
  • 26. Converters & Validation II JSF Parts Con. 26 • Lets Take Some examples • How to customize the Messages ? – Create a properties file named “MyMessage.properties for example” (can be any name you like) as below.
  • 27. Converters & Validation III JSF Parts Con. 27 • How to customize the Messages ? – Create a properties file named “MyMessage.properties for example” (can be any name you like) as below. – Register Message Bundle in faces-config.xml file
  • 28. New Features in JSF 2.2 28 • Faces Flows (something like ADF task flow) This feature gives the developer the ability to develop flows that can be packaged in a JAR file and then be distributed in any application that wishes to use it. • HTML5 support (write HTML not JSF component)
  • 29. New Features in JSF 2.2 Con. 29 • File Upload Component This feature makes it possible to upload a file from a JSF page. • Stateless JSF This feature allows you to mark a Facelets page as being stateless, which means no view state is saved for the page. Increasing the performance just if you don’t want the state