SlideShare ist ein Scribd-Unternehmen logo
1 von 36
Downloaden Sie, um offline zu lesen
Introduction to
Java Server Faces(JSF)
Deepak Goyal
Vikas Varma
Sun Microsystems
2
Objective
Understand the basic concepts of
Java Server™ Faces[JSF]
Technology.
 What is and why JSF?
 Architecture Overview
 UI Component Model
 Development Steps
Agenda
4
JavaServer™ Faces (JSF)
Framework Is…
A server side user interface
component framework for Java™
technology-based web applications
5
What is JSF?
● A specification and reference
implementation for a web application
development framework
– Components
– Events
– Validators & converters
– Navigation
– Back-end-data integration
6
Why JSF? (page 1)
● MVC for web applications
● Clean separation of roles
● Easy to use
● Extendable Component and Rendering
architecture
● Support for client device independence
● Standard
● Huge vendor and industry support
7
Why JSF? (page 2)
● JSP and Servlet
– No built-in UI component model
● Struts (I am not saying you should not use Struts)
– No built-in UI component model
– No built-in event model for UI components
– No built-in state management for UI components
– No built-in support of multiple renderers
– Not a standard (despite its popularity)
● Struts and JSF can be used together
8
How the JSF Specification Fits In
JSF App
Servlets (2.3)
JSP (1.2) JSF API
JSF Tags
JSF App
 What is and why JSF?
 Architecture Overview
 UI Component Model
 Development Steps
Agenda
10
JSF Architecture [MVC]
HTML
RenderKit
App
Backend
Desktop
Browser
Phone
Front
ctrl
JSF Page
JSF Page
WML
HTML
Server
WML
RenderKit
Request processing Lifecycle
FacesServlet
FacesContext
1.Creates FacesContext
Lifecycle
2.Passes controls to Lifecycle
3. Process FacesContext in various phase
12
Request Processing Lifecycle Phases
Faces
Request Reconstitute
Component
Tree
Apply
Request
Values
Process
Validations
Faces
Response Render
Response
Invoke
Application
Update
Model
Values
13
Request Processing Lifecycle
Faces
Request Reconstitute
Component
Tree
Apply
Request
Values
Process
Events
Process
Validations
Process
Events
Response
Complete
Response
Complete
Render Response
Response
Complete
Response
Complete
Faces
Response Render
Responder
Invoke
Application
Update
Model
Values
Process
Events
Process
Events
Conversion Errors /
Render Response
Validation / Conversion
Errors / Render Response
14
Request Processing Lifecycle
Phases
1.Reconstitute component tree phase
2.Apply request values phase
3.Process validations phase
4.Update model values phase
5.Invoke application phase
6.Render response phase
 What is and why JSF?
 Architecture Overview
 UI Component Model
 Development Steps
Agenda
16
User Interface Component Model
● UI components
● Event handling model
● Conversion and Validation model
● Rendering model
● Page navigation support
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="userNo"
value="#{UserNumberBean.userNumber}"/>
Validators and Converters
 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
 Converters—Plug-in for conversions:
 Output: Object to String
 Input: String to Object
 Standard implementations for common cases
Converters and Validators
Example:
Converters:
<h:input_text valueRef=”testingBean.today”
convertor=”DateTime”/>
Validators:
<h:input_text valueRef=”testingBean.today”
<f:validator_length minimum=”6” maximum='10” />
Rendering Model
 Renderers-Adapt components to a specific markup
language
 Decoding
 Encoding
 RenderKits—Library of Renderers
 Map component classes to component tags
 Is a custom tag library
 Basic HTML RenderKit
Events and Listeners
 Follows JavaBeans™ Specification design and
naming patterns
 Standard events and listeners
 ActionEvent—UICommand component activated
by the user
 ValueChangedEvent—UIInput component whose
value was just changed
Navigation Model
 Application developer responsibility
 Defined in Application configuration file
(Facesconfig.xml)
 Navigation rules
 Determine which page to go.
 Navigation case
Navigation Model
<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>
 What is and why JSF?
 Architecture Overview
 UI Component Model
 Development Steps
Agenda
Steps in Development Process
1. Develop model objects which hold the data
2. Add model objects (managed bean) declarations to
Application Configuration File faces-config.xml
3. Create Pages using UI component and core tags
4. Define Page Navigation in faces-config.xml
5. Configure web.xml
Step1: Develop model Objects
(Managed Bean)
 The model (M) in MVC
 A regular JavaBeans with read/write properties
 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
Step 2. Managed Bean Declaration
(Faces-config.xml)
01 <managed-bean>
02 <managed-bean-name>
03 LoginFormBean
04 </managed-bean-name>
05 <managed-bean-class>
06 myapp.LoginFormBean
07 </managed-bean-class>
08 <managed-bean-scope>
09 request
10 </managed-bean-scope>
11 </managed-bean>
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
Sample JSF™ Page (login.jsp)
01 <f:view>
02 <f:form formName=”logonForm”>
03 <h:panel_grid columns=”2”>
04 <h:output_text value=”Username:”/>
05 <h:input_text id=”username” length=”16”
06 valueRef=”logonBean.username”/>
07 <h:output_text value=”Password:”/>
08 <h:input_secret id=”password” length=”16”
09 valueRef=”logonBean.password”/>
10 <h:command_button type=”submit”
11 label=”Log On”
12 actionRef=”logonBean.logon”/>
13 <h:command_button type=”reset”
14 label=”Reset”/>
15 </h:panel_grid>
16 </f:form>
17 </f:view>
Binding UI to Managed Bean
<h:input_text id=”userName”
valueRef=”LoginFormBean.userName”/>
<managed-bean>
<managed-bean-name>
LoginFormBean
</managed-bean-name>
<managed-bean-class>
myapp.LoginFormBean
</managed-bean-class>
public class LoginFormBean
...
public void
setUserName(...) {
public String
getUserName(...) {
faces-config.xml
login.jsp
LoginFormBean.java
Step 4: Define Page Navigation Rules
(Faces-config.xml)
01 <navigation-rule>
02 <from-tree-id>/login.jsp</from-tree-id>
03 <navigation-case>
04 <from-outcome>success</from-outcome>
05 <to-tree-id>/menu.jsp</to-tree-id>
06 </navigation-case>
07 </navigation-rule>
08
09 <navigation-rule>
010 <from-tree-id>/login.jsp</from-tree-id>
011 <navigation-case>
012 <from-outcome>failure</from-outcome>
013 <to-tree-id>/error.jsp</to-tree-id>
014 </navigation-case>
015 </navigation-rule>
Step 5: Configure (web.xml)
01 <context-param>
02 <param-name>
03 javax.faces.application.CONFIG_FILES
04 </param-name>
05 <param-value>/WEB-INF/faces-config.xml
06 </param-value>
07 </context-param>
08 <servlet>
09 <servlet-name>Faces Servlet</servlet-name>
10 <servlet-class>
11 javax.faces.webapp.FacesServlet</servlet-class>
12 <load-on-startup> 1 </load-on-startup>
13 </servlet>
14 <!-- Faces Servlet Mapping -->
15 <servlet-mapping>
16 <servlet-name>Faces Servlet</servlet-name>
17 <url-pattern>/faces/*</url-pattern>
18 </servlet-mapping>
JSF Application directory structure
WEB-INF/web.xml
WEB-INF/faces-config.xml
WEB-INF/classes/LoginFormBean.class
login.jsp
Required Jars:
WEB-INF/lib/jsf-api.jar
WEB-INF/lib/jsf-ri.jar
WEB-INF/lib/jstl.jar
WEB-INF/lib/jsf-el.jar
WEB-INF/lib/standard.jar
WEB-INF/lib/commons-beanutils.jar
WEB-INF/lib/commons-digester.jar
WEB-INF/lib/commons-collections.jar
WEB-INF/lib/commons-logging.jar
 JSF: Server side UI component framework
 MVC
 Developing application in JSF
Summary
Reference
 http://www.jsfcentral.com/reading/index.html
 http://java.sun.com/j2ee/javaserverfaces/
 http://www.jcp.org/en/jsr/detail?id=127
Q&A
deepak.goyal@sun.com
vikas.varma@sun.com

Weitere ähnliche Inhalte

Was ist angesagt?

Introduction to JSF
Introduction toJSFIntroduction toJSF
Introduction to JSFSoftServe
 
Sun JSF Presentation
Sun JSF PresentationSun JSF Presentation
Sun JSF PresentationGaurav Dighe
 
JSF Component Behaviors
JSF Component BehaviorsJSF Component Behaviors
JSF Component BehaviorsAndy Schwartz
 
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
 
9. java server faces
9. java server faces9. java server faces
9. java server facesAnusAhmad
 
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
 
Java Web Programming [6/9] : MVC
Java Web Programming [6/9] : MVCJava Web Programming [6/9] : MVC
Java Web Programming [6/9] : MVCIMC Institute
 
Spring MVC
Spring MVCSpring MVC
Spring MVCyuvalb
 
Struts An Open-source Architecture for Web Applications
Struts An Open-source Architecture for Web ApplicationsStruts An Open-source Architecture for Web Applications
Struts An Open-source Architecture for Web Applicationselliando dias
 
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
 

Was ist angesagt? (20)

Introduction to JSF
Introduction toJSFIntroduction toJSF
Introduction to JSF
 
Sun JSF Presentation
Sun JSF PresentationSun JSF Presentation
Sun JSF Presentation
 
JSF Component Behaviors
JSF Component BehaviorsJSF Component Behaviors
JSF Component Behaviors
 
Jsf2.0 -4
Jsf2.0 -4Jsf2.0 -4
Jsf2.0 -4
 
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
 
9. java server faces
9. java server faces9. java server faces
9. java server faces
 
Struts Introduction Course
Struts Introduction CourseStruts Introduction Course
Struts Introduction Course
 
Jsf
JsfJsf
Jsf
 
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
 
Struts course material
Struts course materialStruts course material
Struts course material
 
Java Web Programming [6/9] : MVC
Java Web Programming [6/9] : MVCJava Web Programming [6/9] : MVC
Java Web Programming [6/9] : MVC
 
Spring Web MVC
Spring Web MVCSpring Web MVC
Spring Web MVC
 
Spring MVC
Spring MVCSpring MVC
Spring MVC
 
Spring mvc
Spring mvcSpring mvc
Spring mvc
 
Struts An Open-source Architecture for Web Applications
Struts An Open-source Architecture for Web ApplicationsStruts An Open-source Architecture for Web Applications
Struts An Open-source Architecture for Web Applications
 
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
 
Jsf
JsfJsf
Jsf
 
AK 4 JSF
AK 4 JSFAK 4 JSF
AK 4 JSF
 

Ähnlich wie Java server faces

AK 5 JSF 21 july 2008
AK 5 JSF   21 july 2008AK 5 JSF   21 july 2008
AK 5 JSF 21 july 2008gauravashq
 
Model View Presenter
Model View Presenter Model View Presenter
Model View Presenter rendra toro
 
MVVM ( Model View ViewModel )
MVVM ( Model View ViewModel )MVVM ( Model View ViewModel )
MVVM ( Model View ViewModel )Ahmed Emad
 
CTTDNUG ASP.NET MVC
CTTDNUG ASP.NET MVCCTTDNUG ASP.NET MVC
CTTDNUG ASP.NET MVCBarry Gervin
 
Introduction to Angularjs : kishan kumar
Introduction to Angularjs : kishan kumarIntroduction to Angularjs : kishan kumar
Introduction to Angularjs : kishan kumarAppfinz Technologies
 
Web tier-framework-mvc
Web tier-framework-mvcWeb tier-framework-mvc
Web tier-framework-mvcKashfUlHuda1
 
Adf coursecontent(1)
Adf coursecontent(1)Adf coursecontent(1)
Adf coursecontent(1)Amit Sharma
 
Introduction to j2 ee frameworks
Introduction to j2 ee frameworksIntroduction to j2 ee frameworks
Introduction to j2 ee frameworksMukesh Kumar
 
Developing Next-Gen Enterprise Web Application
Developing Next-Gen Enterprise Web ApplicationDeveloping Next-Gen Enterprise Web Application
Developing Next-Gen Enterprise Web ApplicationMark Gu
 
Building a Web-bridge for JADE agents
Building a Web-bridge for JADE agentsBuilding a Web-bridge for JADE agents
Building a Web-bridge for JADE agentsinfopapers
 
Mt ADF 001 adf-course outlines
Mt ADF 001 adf-course outlinesMt ADF 001 adf-course outlines
Mt ADF 001 adf-course outlinesAbbas Qureshi
 
Introduction to ejb and struts framework
Introduction to ejb and struts frameworkIntroduction to ejb and struts framework
Introduction to ejb and struts frameworks4al_com
 
Rendra Toro - Model View Presenter
Rendra Toro - Model View PresenterRendra Toro - Model View Presenter
Rendra Toro - Model View PresenterDicoding
 

Ähnlich wie Java server faces (20)

Jsf 2
Jsf 2Jsf 2
Jsf 2
 
JSF Presentation"2"
JSF Presentation"2"JSF Presentation"2"
JSF Presentation"2"
 
AK 5 JSF 21 july 2008
AK 5 JSF   21 july 2008AK 5 JSF   21 july 2008
AK 5 JSF 21 july 2008
 
Design patterns
Design patternsDesign patterns
Design patterns
 
Model View Presenter
Model View Presenter Model View Presenter
Model View Presenter
 
MVVM ( Model View ViewModel )
MVVM ( Model View ViewModel )MVVM ( Model View ViewModel )
MVVM ( Model View ViewModel )
 
MVC
MVCMVC
MVC
 
An Oracle ADF Introduction
An Oracle ADF IntroductionAn Oracle ADF Introduction
An Oracle ADF Introduction
 
CTTDNUG ASP.NET MVC
CTTDNUG ASP.NET MVCCTTDNUG ASP.NET MVC
CTTDNUG ASP.NET MVC
 
Introduction to Angularjs : kishan kumar
Introduction to Angularjs : kishan kumarIntroduction to Angularjs : kishan kumar
Introduction to Angularjs : kishan kumar
 
Introduction to Angularjs
Introduction to AngularjsIntroduction to Angularjs
Introduction to Angularjs
 
Web tier-framework-mvc
Web tier-framework-mvcWeb tier-framework-mvc
Web tier-framework-mvc
 
Adf coursecontent(1)
Adf coursecontent(1)Adf coursecontent(1)
Adf coursecontent(1)
 
Introduction to j2 ee frameworks
Introduction to j2 ee frameworksIntroduction to j2 ee frameworks
Introduction to j2 ee frameworks
 
Developing Next-Gen Enterprise Web Application
Developing Next-Gen Enterprise Web ApplicationDeveloping Next-Gen Enterprise Web Application
Developing Next-Gen Enterprise Web Application
 
Building a Web-bridge for JADE agents
Building a Web-bridge for JADE agentsBuilding a Web-bridge for JADE agents
Building a Web-bridge for JADE agents
 
Mt ADF 001 adf-course outlines
Mt ADF 001 adf-course outlinesMt ADF 001 adf-course outlines
Mt ADF 001 adf-course outlines
 
Introduction to ejb and struts framework
Introduction to ejb and struts frameworkIntroduction to ejb and struts framework
Introduction to ejb and struts framework
 
Rendra Toro - Model View Presenter
Rendra Toro - Model View PresenterRendra Toro - Model View Presenter
Rendra Toro - Model View Presenter
 
Krishnagopal Thogiti_Java
Krishnagopal Thogiti_JavaKrishnagopal Thogiti_Java
Krishnagopal Thogiti_Java
 

Kürzlich hochgeladen

Advanced Views - Calendar View in Odoo 17
Advanced Views - Calendar View in Odoo 17Advanced Views - Calendar View in Odoo 17
Advanced Views - Calendar View in Odoo 17Celine George
 
Introduction to Nonprofit Accounting: The Basics
Introduction to Nonprofit Accounting: The BasicsIntroduction to Nonprofit Accounting: The Basics
Introduction to Nonprofit Accounting: The BasicsTechSoup
 
Beyond the EU: DORA and NIS 2 Directive's Global Impact
Beyond the EU: DORA and NIS 2 Directive's Global ImpactBeyond the EU: DORA and NIS 2 Directive's Global Impact
Beyond the EU: DORA and NIS 2 Directive's Global ImpactPECB
 
General Principles of Intellectual Property: Concepts of Intellectual Proper...
General Principles of Intellectual Property: Concepts of Intellectual  Proper...General Principles of Intellectual Property: Concepts of Intellectual  Proper...
General Principles of Intellectual Property: Concepts of Intellectual Proper...Poonam Aher Patil
 
Measures of Central Tendency: Mean, Median and Mode
Measures of Central Tendency: Mean, Median and ModeMeasures of Central Tendency: Mean, Median and Mode
Measures of Central Tendency: Mean, Median and ModeThiyagu K
 
Seal of Good Local Governance (SGLG) 2024Final.pptx
Seal of Good Local Governance (SGLG) 2024Final.pptxSeal of Good Local Governance (SGLG) 2024Final.pptx
Seal of Good Local Governance (SGLG) 2024Final.pptxnegromaestrong
 
Activity 01 - Artificial Culture (1).pdf
Activity 01 - Artificial Culture (1).pdfActivity 01 - Artificial Culture (1).pdf
Activity 01 - Artificial Culture (1).pdfciinovamais
 
TỔNG ÔN TẬP THI VÀO LỚP 10 MÔN TIẾNG ANH NĂM HỌC 2023 - 2024 CÓ ĐÁP ÁN (NGỮ Â...
TỔNG ÔN TẬP THI VÀO LỚP 10 MÔN TIẾNG ANH NĂM HỌC 2023 - 2024 CÓ ĐÁP ÁN (NGỮ Â...TỔNG ÔN TẬP THI VÀO LỚP 10 MÔN TIẾNG ANH NĂM HỌC 2023 - 2024 CÓ ĐÁP ÁN (NGỮ Â...
TỔNG ÔN TẬP THI VÀO LỚP 10 MÔN TIẾNG ANH NĂM HỌC 2023 - 2024 CÓ ĐÁP ÁN (NGỮ Â...Nguyen Thanh Tu Collection
 
microwave assisted reaction. General introduction
microwave assisted reaction. General introductionmicrowave assisted reaction. General introduction
microwave assisted reaction. General introductionMaksud Ahmed
 
Making and Justifying Mathematical Decisions.pdf
Making and Justifying Mathematical Decisions.pdfMaking and Justifying Mathematical Decisions.pdf
Making and Justifying Mathematical Decisions.pdfChris Hunter
 
ComPTIA Overview | Comptia Security+ Book SY0-701
ComPTIA Overview | Comptia Security+ Book SY0-701ComPTIA Overview | Comptia Security+ Book SY0-701
ComPTIA Overview | Comptia Security+ Book SY0-701bronxfugly43
 
Mixin Classes in Odoo 17 How to Extend Models Using Mixin Classes
Mixin Classes in Odoo 17  How to Extend Models Using Mixin ClassesMixin Classes in Odoo 17  How to Extend Models Using Mixin Classes
Mixin Classes in Odoo 17 How to Extend Models Using Mixin ClassesCeline George
 
How to Give a Domain for a Field in Odoo 17
How to Give a Domain for a Field in Odoo 17How to Give a Domain for a Field in Odoo 17
How to Give a Domain for a Field in Odoo 17Celine George
 
Food Chain and Food Web (Ecosystem) EVS, B. Pharmacy 1st Year, Sem-II
Food Chain and Food Web (Ecosystem) EVS, B. Pharmacy 1st Year, Sem-IIFood Chain and Food Web (Ecosystem) EVS, B. Pharmacy 1st Year, Sem-II
Food Chain and Food Web (Ecosystem) EVS, B. Pharmacy 1st Year, Sem-IIShubhangi Sonawane
 
Z Score,T Score, Percential Rank and Box Plot Graph
Z Score,T Score, Percential Rank and Box Plot GraphZ Score,T Score, Percential Rank and Box Plot Graph
Z Score,T Score, Percential Rank and Box Plot GraphThiyagu K
 
Nutritional Needs Presentation - HLTH 104
Nutritional Needs Presentation - HLTH 104Nutritional Needs Presentation - HLTH 104
Nutritional Needs Presentation - HLTH 104misteraugie
 
Energy Resources. ( B. Pharmacy, 1st Year, Sem-II) Natural Resources
Energy Resources. ( B. Pharmacy, 1st Year, Sem-II) Natural ResourcesEnergy Resources. ( B. Pharmacy, 1st Year, Sem-II) Natural Resources
Energy Resources. ( B. Pharmacy, 1st Year, Sem-II) Natural ResourcesShubhangi Sonawane
 
ICT Role in 21st Century Education & its Challenges.pptx
ICT Role in 21st Century Education & its Challenges.pptxICT Role in 21st Century Education & its Challenges.pptx
ICT Role in 21st Century Education & its Challenges.pptxAreebaZafar22
 
Explore beautiful and ugly buildings. Mathematics helps us create beautiful d...
Explore beautiful and ugly buildings. Mathematics helps us create beautiful d...Explore beautiful and ugly buildings. Mathematics helps us create beautiful d...
Explore beautiful and ugly buildings. Mathematics helps us create beautiful d...christianmathematics
 

Kürzlich hochgeladen (20)

Advanced Views - Calendar View in Odoo 17
Advanced Views - Calendar View in Odoo 17Advanced Views - Calendar View in Odoo 17
Advanced Views - Calendar View in Odoo 17
 
Introduction to Nonprofit Accounting: The Basics
Introduction to Nonprofit Accounting: The BasicsIntroduction to Nonprofit Accounting: The Basics
Introduction to Nonprofit Accounting: The Basics
 
Beyond the EU: DORA and NIS 2 Directive's Global Impact
Beyond the EU: DORA and NIS 2 Directive's Global ImpactBeyond the EU: DORA and NIS 2 Directive's Global Impact
Beyond the EU: DORA and NIS 2 Directive's Global Impact
 
General Principles of Intellectual Property: Concepts of Intellectual Proper...
General Principles of Intellectual Property: Concepts of Intellectual  Proper...General Principles of Intellectual Property: Concepts of Intellectual  Proper...
General Principles of Intellectual Property: Concepts of Intellectual Proper...
 
Measures of Central Tendency: Mean, Median and Mode
Measures of Central Tendency: Mean, Median and ModeMeasures of Central Tendency: Mean, Median and Mode
Measures of Central Tendency: Mean, Median and Mode
 
Seal of Good Local Governance (SGLG) 2024Final.pptx
Seal of Good Local Governance (SGLG) 2024Final.pptxSeal of Good Local Governance (SGLG) 2024Final.pptx
Seal of Good Local Governance (SGLG) 2024Final.pptx
 
Activity 01 - Artificial Culture (1).pdf
Activity 01 - Artificial Culture (1).pdfActivity 01 - Artificial Culture (1).pdf
Activity 01 - Artificial Culture (1).pdf
 
TỔNG ÔN TẬP THI VÀO LỚP 10 MÔN TIẾNG ANH NĂM HỌC 2023 - 2024 CÓ ĐÁP ÁN (NGỮ Â...
TỔNG ÔN TẬP THI VÀO LỚP 10 MÔN TIẾNG ANH NĂM HỌC 2023 - 2024 CÓ ĐÁP ÁN (NGỮ Â...TỔNG ÔN TẬP THI VÀO LỚP 10 MÔN TIẾNG ANH NĂM HỌC 2023 - 2024 CÓ ĐÁP ÁN (NGỮ Â...
TỔNG ÔN TẬP THI VÀO LỚP 10 MÔN TIẾNG ANH NĂM HỌC 2023 - 2024 CÓ ĐÁP ÁN (NGỮ Â...
 
microwave assisted reaction. General introduction
microwave assisted reaction. General introductionmicrowave assisted reaction. General introduction
microwave assisted reaction. General introduction
 
Making and Justifying Mathematical Decisions.pdf
Making and Justifying Mathematical Decisions.pdfMaking and Justifying Mathematical Decisions.pdf
Making and Justifying Mathematical Decisions.pdf
 
ComPTIA Overview | Comptia Security+ Book SY0-701
ComPTIA Overview | Comptia Security+ Book SY0-701ComPTIA Overview | Comptia Security+ Book SY0-701
ComPTIA Overview | Comptia Security+ Book SY0-701
 
Mixin Classes in Odoo 17 How to Extend Models Using Mixin Classes
Mixin Classes in Odoo 17  How to Extend Models Using Mixin ClassesMixin Classes in Odoo 17  How to Extend Models Using Mixin Classes
Mixin Classes in Odoo 17 How to Extend Models Using Mixin Classes
 
How to Give a Domain for a Field in Odoo 17
How to Give a Domain for a Field in Odoo 17How to Give a Domain for a Field in Odoo 17
How to Give a Domain for a Field in Odoo 17
 
Food Chain and Food Web (Ecosystem) EVS, B. Pharmacy 1st Year, Sem-II
Food Chain and Food Web (Ecosystem) EVS, B. Pharmacy 1st Year, Sem-IIFood Chain and Food Web (Ecosystem) EVS, B. Pharmacy 1st Year, Sem-II
Food Chain and Food Web (Ecosystem) EVS, B. Pharmacy 1st Year, Sem-II
 
INDIA QUIZ 2024 RLAC DELHI UNIVERSITY.pptx
INDIA QUIZ 2024 RLAC DELHI UNIVERSITY.pptxINDIA QUIZ 2024 RLAC DELHI UNIVERSITY.pptx
INDIA QUIZ 2024 RLAC DELHI UNIVERSITY.pptx
 
Z Score,T Score, Percential Rank and Box Plot Graph
Z Score,T Score, Percential Rank and Box Plot GraphZ Score,T Score, Percential Rank and Box Plot Graph
Z Score,T Score, Percential Rank and Box Plot Graph
 
Nutritional Needs Presentation - HLTH 104
Nutritional Needs Presentation - HLTH 104Nutritional Needs Presentation - HLTH 104
Nutritional Needs Presentation - HLTH 104
 
Energy Resources. ( B. Pharmacy, 1st Year, Sem-II) Natural Resources
Energy Resources. ( B. Pharmacy, 1st Year, Sem-II) Natural ResourcesEnergy Resources. ( B. Pharmacy, 1st Year, Sem-II) Natural Resources
Energy Resources. ( B. Pharmacy, 1st Year, Sem-II) Natural Resources
 
ICT Role in 21st Century Education & its Challenges.pptx
ICT Role in 21st Century Education & its Challenges.pptxICT Role in 21st Century Education & its Challenges.pptx
ICT Role in 21st Century Education & its Challenges.pptx
 
Explore beautiful and ugly buildings. Mathematics helps us create beautiful d...
Explore beautiful and ugly buildings. Mathematics helps us create beautiful d...Explore beautiful and ugly buildings. Mathematics helps us create beautiful d...
Explore beautiful and ugly buildings. Mathematics helps us create beautiful d...
 

Java server faces

  • 1. Introduction to Java Server Faces(JSF) Deepak Goyal Vikas Varma Sun Microsystems
  • 2. 2 Objective Understand the basic concepts of Java Server™ Faces[JSF] Technology.
  • 3.  What is and why JSF?  Architecture Overview  UI Component Model  Development Steps Agenda
  • 4. 4 JavaServer™ Faces (JSF) Framework Is… A server side user interface component framework for Java™ technology-based web applications
  • 5. 5 What is JSF? ● A specification and reference implementation for a web application development framework – Components – Events – Validators & converters – Navigation – Back-end-data integration
  • 6. 6 Why JSF? (page 1) ● MVC for web applications ● Clean separation of roles ● Easy to use ● Extendable Component and Rendering architecture ● Support for client device independence ● Standard ● Huge vendor and industry support
  • 7. 7 Why JSF? (page 2) ● JSP and Servlet – No built-in UI component model ● Struts (I am not saying you should not use Struts) – No built-in UI component model – No built-in event model for UI components – No built-in state management for UI components – No built-in support of multiple renderers – Not a standard (despite its popularity) ● Struts and JSF can be used together
  • 8. 8 How the JSF Specification Fits In JSF App Servlets (2.3) JSP (1.2) JSF API JSF Tags JSF App
  • 9.  What is and why JSF?  Architecture Overview  UI Component Model  Development Steps Agenda
  • 11. Request processing Lifecycle FacesServlet FacesContext 1.Creates FacesContext Lifecycle 2.Passes controls to Lifecycle 3. Process FacesContext in various phase
  • 12. 12 Request Processing Lifecycle Phases Faces Request Reconstitute Component Tree Apply Request Values Process Validations Faces Response Render Response Invoke Application Update Model Values
  • 13. 13 Request Processing Lifecycle Faces Request Reconstitute Component Tree Apply Request Values Process Events Process Validations Process Events Response Complete Response Complete Render Response Response Complete Response Complete Faces Response Render Responder Invoke Application Update Model Values Process Events Process Events Conversion Errors / Render Response Validation / Conversion Errors / Render Response
  • 14. 14 Request Processing Lifecycle Phases 1.Reconstitute component tree phase 2.Apply request values phase 3.Process validations phase 4.Update model values phase 5.Invoke application phase 6.Render response phase
  • 15.  What is and why JSF?  Architecture Overview  UI Component Model  Development Steps Agenda
  • 16. 16 User Interface Component Model ● UI components ● Event handling model ● Conversion and Validation model ● Rendering model ● Page navigation support
  • 17. 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="userNo" value="#{UserNumberBean.userNumber}"/>
  • 18. Validators and Converters  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  Converters—Plug-in for conversions:  Output: Object to String  Input: String to Object  Standard implementations for common cases
  • 19. Converters and Validators Example: Converters: <h:input_text valueRef=”testingBean.today” convertor=”DateTime”/> Validators: <h:input_text valueRef=”testingBean.today” <f:validator_length minimum=”6” maximum='10” />
  • 20. Rendering Model  Renderers-Adapt components to a specific markup language  Decoding  Encoding  RenderKits—Library of Renderers  Map component classes to component tags  Is a custom tag library  Basic HTML RenderKit
  • 21. Events and Listeners  Follows JavaBeans™ Specification design and naming patterns  Standard events and listeners  ActionEvent—UICommand component activated by the user  ValueChangedEvent—UIInput component whose value was just changed
  • 22. Navigation Model  Application developer responsibility  Defined in Application configuration file (Facesconfig.xml)  Navigation rules  Determine which page to go.  Navigation case
  • 24.  What is and why JSF?  Architecture Overview  UI Component Model  Development Steps Agenda
  • 25. Steps in Development Process 1. Develop model objects which hold the data 2. Add model objects (managed bean) declarations to Application Configuration File faces-config.xml 3. Create Pages using UI component and core tags 4. Define Page Navigation in faces-config.xml 5. Configure web.xml
  • 26. Step1: Develop model Objects (Managed Bean)  The model (M) in MVC  A regular JavaBeans with read/write properties  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
  • 27. Step 2. Managed Bean Declaration (Faces-config.xml) 01 <managed-bean> 02 <managed-bean-name> 03 LoginFormBean 04 </managed-bean-name> 05 <managed-bean-class> 06 myapp.LoginFormBean 07 </managed-bean-class> 08 <managed-bean-scope> 09 request 10 </managed-bean-scope> 11 </managed-bean>
  • 28. 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
  • 29. Sample JSF™ Page (login.jsp) 01 <f:view> 02 <f:form formName=”logonForm”> 03 <h:panel_grid columns=”2”> 04 <h:output_text value=”Username:”/> 05 <h:input_text id=”username” length=”16” 06 valueRef=”logonBean.username”/> 07 <h:output_text value=”Password:”/> 08 <h:input_secret id=”password” length=”16” 09 valueRef=”logonBean.password”/> 10 <h:command_button type=”submit” 11 label=”Log On” 12 actionRef=”logonBean.logon”/> 13 <h:command_button type=”reset” 14 label=”Reset”/> 15 </h:panel_grid> 16 </f:form> 17 </f:view>
  • 30. Binding UI to Managed Bean <h:input_text id=”userName” valueRef=”LoginFormBean.userName”/> <managed-bean> <managed-bean-name> LoginFormBean </managed-bean-name> <managed-bean-class> myapp.LoginFormBean </managed-bean-class> public class LoginFormBean ... public void setUserName(...) { public String getUserName(...) { faces-config.xml login.jsp LoginFormBean.java
  • 31. Step 4: Define Page Navigation Rules (Faces-config.xml) 01 <navigation-rule> 02 <from-tree-id>/login.jsp</from-tree-id> 03 <navigation-case> 04 <from-outcome>success</from-outcome> 05 <to-tree-id>/menu.jsp</to-tree-id> 06 </navigation-case> 07 </navigation-rule> 08 09 <navigation-rule> 010 <from-tree-id>/login.jsp</from-tree-id> 011 <navigation-case> 012 <from-outcome>failure</from-outcome> 013 <to-tree-id>/error.jsp</to-tree-id> 014 </navigation-case> 015 </navigation-rule>
  • 32. Step 5: Configure (web.xml) 01 <context-param> 02 <param-name> 03 javax.faces.application.CONFIG_FILES 04 </param-name> 05 <param-value>/WEB-INF/faces-config.xml 06 </param-value> 07 </context-param> 08 <servlet> 09 <servlet-name>Faces Servlet</servlet-name> 10 <servlet-class> 11 javax.faces.webapp.FacesServlet</servlet-class> 12 <load-on-startup> 1 </load-on-startup> 13 </servlet> 14 <!-- Faces Servlet Mapping --> 15 <servlet-mapping> 16 <servlet-name>Faces Servlet</servlet-name> 17 <url-pattern>/faces/*</url-pattern> 18 </servlet-mapping>
  • 33. JSF Application directory structure WEB-INF/web.xml WEB-INF/faces-config.xml WEB-INF/classes/LoginFormBean.class login.jsp Required Jars: WEB-INF/lib/jsf-api.jar WEB-INF/lib/jsf-ri.jar WEB-INF/lib/jstl.jar WEB-INF/lib/jsf-el.jar WEB-INF/lib/standard.jar WEB-INF/lib/commons-beanutils.jar WEB-INF/lib/commons-digester.jar WEB-INF/lib/commons-collections.jar WEB-INF/lib/commons-logging.jar
  • 34.  JSF: Server side UI component framework  MVC  Developing application in JSF Summary