JavaServer
Faces
2.0:
The
Complete
Reference
TIB/UB Hannover 89 133 219 50X
Contents
Acknowledgments
xxiiiIntroduction
, xxv
Part §
The JavaServer
Faces Framework1 Introductionto
JavaServer
Faces 3What Is
JavaServer
Faces? 3The
History
ofJavaServer
Faces . 4TheCommon
Gateway
Interface , 4TheServlet API
5
JavaServer Pages
5Apache
Struts 6The
Spring
Framework andSpring
MVC 6The Birth of
JavaServer
Faces 6The
JavaServer
FacesDesign
Goals 7JSF
Application
Architecture 9The
JSF
Request
Processing Lifecycle
. 10The
JSF Navigation
Model 122
Building
aSimple
JavaServer
FacesApplication
. 15Application
Overview 15The
JSFReg Application
Files 16The
JSF
Software Stack 17Assembling
theJSFReg Application
18The
Configuration
File 19TheFacelets
Pages
20Building
andRunning
theApplication
30Deploying
andRunning
theApplication
32Reviewing
theKey
Portionsof theApplication
323 The
JavaServer
FacesRequest Processing Lifecycle
35A
High-Level
Overview of theJSF
Request Processing Lifecycle
35What
Exactly
DoestheRequest Processing Lifecycle
Do? 36 HowDoes It DifferfromOtherWebTechnologies?
36 Automatic Server-SideViewManagement
andSynchronization
... 37The
Request Processing Lifecycle
Phases .. 38Observing
theRequest Processing Lifecycle
in Action 46 AdvancedTopics
RelatedtotheRequest Processing Lifecycle
... 50Using
the immediate Attribute 50X JavaServer Faces 2.0: The
Complete
ReferencePhaseListeners 52
Exception
Handler 52Lifecycle
Concepts
toRemember 534 TheFacelets View Declaration
Language
55ThePower of
Templating
in Faces 56Similarities and Differences Between
JSP
and Facelets 57Templating
with Facelets 58Guideto Facelets
Templating
Tags
62uixomposition
62 ukdecorate 62 ukdefine 62 ukinserl 62 ui:include 64uiparam
65Guideto
Nontemplating
FaceletsTags
65ukcomponent
65ui:fragment
65ui:remove 65
ukdebug
665
Managed
Beans and theJSF
Expression Language
67What Are
Managed
Beans? 68A
Simple Managed
BeanExample
68Initializing Managed
BeanProperties
70Declaring
Lists andMaps
Directly
asManaged
Beans 78Managed
BeanInterdependence
78Setting
Managed
Properties
Using
EL 80Controlling Managed
Bean LifeSpans
81The
JSF
Expression
Language
84Important Expression Languages
Changes
Between
JSF
1.1 andJSF
1.2 84Unified EL
Concepts
86Value
Expressions
87Expression Operators
93Method
Expressions
94Web
Application Development
Details onManaged
Beans 97HowtoAccess
Managed
BeansProgrammatically
98Using Managed
BeansasBacking
BeansforJSF
Pages
996 The
Navigation
Model 103Using Implicit Navigation
103Overview of the
JSF Navigation System
106Recalling
MVC—The Controller 107The
NavigationHandler—Behind
the Scenes 107Contents
xi
Building
Navigation
Rules 109A Static
Navigation
Example
IllA
Dynamic Navigation Example
112More
Sophisticated
Navigation
Examples
116Using
Wildcards 116Using
ConditionalNavigation
117Using
Redirects 118XML
Configuration
forViewParameters
132Using JSF Components
on a Servlet ErrorPage
1337 The User Interface
Component
Model 135WhatAre UI
Components?
135TheRise of
Component-Based
WebDevelopment
136The Goal of
JavaServer
Faces UIComponents
138Introducing
theJSF
UIComponent
Architecture 138The UI
Component
Tree(View)
143The UI
Component
and ItsAssociated"Moving
Parts" 145Component
Resources 147UI
Components
andFacelets 147Accessing
UIComponents Programmatically
147Helpful
AdviceforBinding
UIComponents
inJSF
Views 1518
Converting
andValidating
Data 155SomeValidation andConversion
Examples
156Conversion andValidation Under the Covers 158
The FacesConverter
System
162DateTimeConverter 163
NumberConverter 164
Associating
aConverter withaUlComponent
Instance 164The Lifetime ofaConverter 170
Custom Converters 170
The Faces Validation
System
175LongRangeValidator
177DoubleRangeValidator
177LengthValidator
177The
"required" Facility
and theRequiredValidator
178RegExValidator
179BeanValidator 179
How toAssociateaValidator witha
UlComponent
Instance 179Using Markup
toAssociateaValidator witha
UlComponent
Instance 180Using Markup
and the validator AttributetoAssociateaValidator witha
UlComponent
Instance 181Programmatically Associating
a Validator withXlj
JavaServer Faces 2.0: TheComplete
ReferenceThe Lifetimeofa Validator 183
Custom Validators 183
Using
Bean ValidationfromJSF
185WhatIsBean Validation? 185
Differences Between
JSF
Validationand BeanValidation 186Details on
Using
Bean Validation fromJSF
187Validating
JSF
Managed
BeanProperties
with Bean Validation .... 189Tie It All
Together: Messages
ina View 190FacesMessage-Related
MethodsonFacesContext 190The UIViewRoot and ItsLocale
Property
192When and How
FacesMessage
InstancesAreCreated and Addedto theFacesContext 192
How
FacesMessages
AreRendered 193Messages
and Bean Validation 1969 The
JSF
EventModel 199A
High-Level
Overview of theJSF
Event Model 199Some Event
Examples
200How
JSF
Events Work 203The Faces Event ListenerInterfacesand EventClasses 204
When AreFacesEventsProcessed? 205
Application
Events 209The
Anatomy
ofaValueChange
Event 211Writing
Custom Action and ValueChange
Listeners 212More Faces Event
Examples
215Using
aValueChange
Event to Auto-FillFields 215Extending
the ValueChange
Example
219Working
with PhaseEvents and Listeners 221Using
aPhaseListener toObserve the FacesLifecycle
in Action .. . 221Working
withSystemEvents
and Listeners 224How
SystemEvents
Are Published 227Howto Subscribe to
SystemEvents
227General Rules for
Creating
CustomApplication
Events and Listeners .... 229Creating
CustomSystemEvent
andComponentSystemEvent
Classes 230Part ii
Extending
JavaServer Faces
10
Applying JSF: Introducing
the VirtualTrainerApplication
235A
Quick
Tourof the VirtualTrainerApplication
236Registering
andLogging
In to theVirtual TrainerApplication
236Creating
aNewTraining
Event WorkoutPlan 237Choosing
Your Trainer 239ActionsAvailable
Only
to Trainers 239The VirtualTrainer
Application Requirements
243Contents
xiii
Facelet
Pages
244Pages
inthe WebApplication
Root 244Pages
in the/user
Directory
244Pages
in the/trainer
Directory
245Pages
in the/
resourcesDirectory
245Backing
Beans , 246Persistence and Transaction
Architecture
248Navigation
Concerns 252Creating
aSimple
AuthenticationSystem
255Revisiting
JSFReg:
Building
theRegistration System
259Building
the CorePages
ofthe Virtual TrainerApplication
263Creating
theallEvents.xhtml
Page
263The TrainerVersion of
editTrainingEvent.xhtml
266Creating
the viewTrainees.xhtmland
viewTrainingSessionsForUser.xhtml Pages
269The
UserRegistry
andEventRegistry
272Accessing
andInitializing
theUserRegistry
Instance 272Reading
andWriting
User Instances 273Reading
andWriting TrainingSession
Instances 275Accessing
andInitializing
theEventRegistry
Instance 277Reading
andWriting
Event Instances 278JPA
and theEntity
Classesin Virtual Trainer 280JPA
XMLConfiguration
File:persistence.xml
281A Custom
ExceptionHandler
Example
282Internationalizing
the VirtualTrainerApplication
284Localization 285
Final CommentsonVirtual Trainer 294
11
Building
Custom UIComponents
295Deciding
Whento Build aCustom UIComponent
295WhatAre UI
Components?
296A
Simple
JSFU1
Component
297The Code Behind the
Markup
of ThisSimple
JSF
UIComponent
299IntroductiontoResource Libraries 300
Adding
BehaviortoaComposite Component
301A First Look into the Details of
Composite Components
303The
#{cc)
Implicit Object
305ThePartsofaUI
Component
306A
Noncomposite
JSF
CustomUlComponent
307Building
theHtmlHelloWorldExample
307AHelloWorld UI
Component
ThatAccepts
FormInput
312A
JSF
StockQuote
Component
314State
Management
with CustomComponents
316Writing
toaStateHelper
317Reading
fromaStateHelper
318Xiv Ja vaSe r v e r Faces 2.0: The
Complete
ReferenceExtracting Rendering
Code into a Renderer 318Creating
a CustomFaceletTag Library TagHandler
320Using
a RenderKit toSupport Multiple
Client DeviceTypes
322Advanced
Composite Component Development
330Creating
aBacking
Class for<vt:loginPanel>
330Composite Component
Feature Review 335Packaging
JSF
Components
into aSelf-ContainedJar
335Packaging
aComposite Component
intoaJar
336Packaging
aComposite
Component
Facelet File 336Declaring
aCustomNamespace
URL fora
Composite Component Library
336Packaging Backing
Classes for aComposite
Component
337Packaging
aNoncomposite
Component
intoaJar
337How the
JSF
RuntimeLoadsfaces-config.xml
Files 337How the
JSP
Runtime Loads T LD Files 33812 JSF and
Aj
ax 339Ajax
Overview 339A
Simple
Ajax
Example
fromJSFReg
341Ajax
JSFReg
Behind theScenes 343The
<f:ajax> Tag
and ItsAttributes 349The Standard
JavaScript
Resource 356Advanced
Topics
onJSF
andAjax
35713
Building
Non-UI CustomComponents
359Non-UICustom
Components
and DecorationinJSF
359Wrapper
Classes 362Non-View Custom
Components Explained
363PhaseListener 363
Interfaceto
Implement
363Registering
aPhaseListener 364Converter and Validator 364
Interfaces to
Implement
364Registering
a ConverterorValidator 365ViewHandler 365
AbstractClasstoExtend 365
Registering
aViewHandler 365VariableResolverand
PropertyResolver
366Abstract Classes toExtend 367
Registering
aVariableResolverorPropertyResolver
368ELResolver(JSF1.2)
369TheELResolver Chain of
Responsibility
369Abstract ClasstoExtend 372
Contents XV
NavigationHandler
378AbstractClass toExtend 378
Registering
aNavigationHandler
orConfigurableNavigationHandler
379 ActionListener 379 Interface toImplement
380Registering
anActionListener 380StateManager
380Abstract Classto Extend in
JSF
1.1 and1.0 380AbstractClassto Extend in
JSF
1.2 382Registering
aStateManager
382 RenderKit 382 Factories inJSF
383Registering
aFactory
384RenderKitFactory
386ExceptionHandlerFactory
388FacesContextFactory
388ExternalContextFactory
389LifecycleFactory
390PartialViewContextFactory
391ViewDeclarationLanguageFactory
391VisitContextFactory
392Application Factory
393Additional
Non-UIComponent
Topics
396Telling
theJSF
Runtime Where You Arein theSoftware
Development Lifecycle:
ProjectStage
396Custom
Scopes
39714
Securing
JavaServer
FacesApplications
399Aspects
andImplementation
of WebApplication Security
399Container-Managed Security
400Container-Managed
Authentication 400BasicAuthentication and the
Concept
ofa "Realm" 401Form-Based Authentication 402
Certificate Authentication 405
Container-Managed
Authorization and theConcept
of Roles 407Container-Managed
DataSecurity
408A Small
Security Improvement
inthe Virtual Trainer 410Application-Managed
Security
withJavaServer
Faces 411Leveraging
J
AAS fromaJSF
Application
411Xvi
JavaServer Faces 2.0: TheComplete
ReferencePart II!
JavaServer
FacesTools and Libraries
15
Configuring
JavaServer
FacesApplications
423Understanding
XML Schemas 425Understanding
HowConfiguration
FilesAreProcessed 425Ordering
offaces-config.xml
Files 426How the
JSF
Runtime ScansClasses forConfiguration
Annotations 427TheFaces
Configuration
Elements 427The
absolute-ordering
Element 437The action-listener Element 437
The
after
Element 438The
application
Element 439The
application-factory
Element 440The attribute Element 440
The attribute-class Element 443
The attribute-name Element 443
The base-name Element 444
The before Element 445
The behavior Element 445
The behavior-class Element 446
The behavior-id Element 447
The client-behavior-renderer Element 448
The client-behavior-renderer-classElement 449
The
client-behavior-renderer-type
Element 449The
component
Element 450The
component-class
Element 451The
component-family
Element 451The
component-type
Element 452The converterElement 453
The converter-class Element 454
The converter-for-dass Element 454
The converter-id Element 455
The default-locale Element 456
The default-render-kit-id Element 457
The default-validators Element 458
The default-value Element 459
The el-resolver Element 460
The
exception-handler-factory
Element 460The
external-context-factory
Element 461 Thefaces-config
Element 462 Thefaces-context-factory
Element 463ThefacetElement 463
The facet-nameElement 465
Contents
xvii
The from-action Element 466
The from-outcome Element 467
Thefrom-view-id Element 467
The if Element 468
The
key
Element 469The
key-class
Element 470 Thelifecycle
Element 471 Thelifecycle-factory
Element 471Thelist-entries Element 472
The
locale-config
Element 473The
managed-bean
Element 474The
managed-bean-class
Element 475The
managed-bean-name
Element 475The
managed-bean-scope
Element 476The
managed-property
Element 477The
map-entries
Element 479The
map-entry
Element 480The
message-bundle
Element 481ThenameElement 482
The
navigation-case
Element 483The
navigation-handler
Element 484The
navigation-rule
Element 485Thenull-value Element 486
The
ordering
Element 488Theothers Element 488
The
partial-view-context-factory
Element 489The
phase-listener
Element 490The
property
Element 491The
property-class
Element 492The
property-name
Element 493The
property-resolver
Element 494The redirect Element 494
The
referenced-bean
Element 495The
referenced-bean-class
Element 496The referenced-bean-name Element 497
The render-kit Element 498
The render-kit-classElement 499
The
render-kit-factory
Element 499The render-kit-idElement 500
TherendererElement 501
Therenderer-classElement 502
The
renderer-type
Element 503Theresource-bundleElement 503
XVlii
JavaServer Faces 2.0: TheComplete
ReferenceThe source-classElement 504
The
state-manager
Element 505The
suggested-value
Element 506The
supported-locale
Element 507The
system-event-class
Element 508The
system-event-listener
Element 509The
system-event-listener-class
Element 510The
tag-handler-delegate-factory
Element 510The to-view-idElement 511
The validator Element 511
Thevalidator-class Element 512
Thevalidator-id Element 513
The valueElement 514
The value-classElement 516
ThevarElement 517
Thevariable-resolver Element 518
The
view-declaration-language-factory
Element 518Theview-handler Element 519
The
view-param
Element 520The
visit-context-factory
Element 521ExtensionElements 521
Metadata Elements 523
16 The Standard
JSF Component Library
525ABrief Review of
JSF, Facelets,
andJSP
Tag
Nomenclature 525Acquiring
andInstalling
the Standard Libraries 526What You Get
(Binary)
527What You Get
(Source)
527The
Tag
Library
Reference 527TheStandard Core
Library
527The hactionListener
Tag
530The
f:ajax
Tag (2.0)
531The f:attribute
Tag
533The fxonvertDateTime
Tag
533The fxonvertNumber
Tag
535The f:converter
Tag
537The f:event
Tag (2.0)
538The f:facet
Tag
538The hloadBundle
Tag
539The ^metadata
Tag (2.0)
540The
f:param
Tag
540The
f:phaseListener
Tag
(1.2,2.0)
541The f:selectltem
Tag
541The hselectltems
Tag
542Contents
The f:subview
Tag
545Thef:validateBeanTag(2.0)
547The
f:validateDoubleRange Tag
549The
f:validateLength Tag
550The
f:validateLongRange Tag
551The
f:validateRegex Tag (2.0)
552The
f:validateRequired Tag (2.0)
552The f:validator
Tag
553The
f:valueChangeListener
Tag
554Thef:verbatim
Tag
555Thef:view
Tag
556The f:viewParam
Tag (2.0)
557The Standard HTML
Library
559Theh:bodyTag(2.0)
562The h:button
Tag
(2.0)
563The h:column
Tag
565The hxommandButton
Tag
567The hxommandLink
Tag
570The h:dataTable
Tag
573Theh:formTag
576The
h:graphiclmage
Tag
578Theh:headTag(2.0)
580The
h:inputHidden Tag
581The
h:inputSecret
Tag
582The
h:inputText
Tag
585The
h:inputTextarea Tag
588The Mink
Tag (2.0)
591The
h:message Tag
594Themessages
Component
596Theh.-outputFormatTag
597The
h:outputLabel Tag
598The
h:outputLink
Tag
600The
h:outputScript Tag (2.0)
602The
h:outputStylesheet Tag (2.0)
603The
h:outputText Tag
605The
h:panelGrid Tag
606The
h:panelGroup Tag
608The hrselectBooleanCheckbox
Tag
609The
h:selectManyCheckbox Tag
612The
h:selectManyListbox Tag
615The
h:selectManyMenu Tag
618The h:selectOneListbox
Tag
621The kselectOneMenu
Tag
624XX lavaServer Faces
2.0:
TheComplete
ReferenceThe Standard Facelets
Templating
Library
(2.0)
631Example
WebsiteProject
632The
uixomponent
Tag
(2.0)
636The ui
composition
Tag (2.0)
637The
ui:debug Tag
(2.0)
637The ui:decorate
Tag
(2.0)
638The ui:define
Tag
(2.0)
639Theui:fragmentTag(2.0)
639The uidnclude
Tag
(2.0)
640The ui:insert
Tag
(2.0)
640The
uiparam Tag
(2.0)
641The ui.'remove
Tag
(2.0)
641The
ui:repeat Tag
(2.0)
642The Standard Facelets
Composite Component Library
(2.0)
643Example Project
645The ccactionSource
Tag
(2.0)
650The ccattribute
Tag
(2.0)
651The cceditableValueHolder
Tag
(2.0)
652Theccextension
Tag (2.0)
653TheccfacetTag (2.0)
654The
complementation Tag
(2.0)
654Thecc.insertChildren
Tag
(2.0)
655The ccinsertFacet
Tag
(2.0)
655The ccinterface
Tag (2.0)
656ThecerenderFacet
Tag (2.0)
657The ccvalueHolder
Tag
(2.0)
658A
JSFPortlets
659Overview of Portlet 1.0 and2.0 659
Portlet
Lifecycle
659Portlet Modes 660
Portlet Window States 661
Portlet Preferences 661
Inter-Portlet Communication 662
JSF
PortletDevelopment
663JSF
PortletBridges
663JSF
Portlet View Handlers 667JSF
ExternalContext and thePortlet API 668JSF
and Portlet Preferences 668JSF
and Inter-Portlet Communication 670ICEfacesPortlet
Development
672ICEfaces
Ajax
with Partial Submit 672ICEfaces Direct-to-DOM RenderKit 673
The
ice:portlet Tag
673Contents
xxi
ICEfaces 1.xD2DFaceletViewHandler 674
ICEfaces 1.x and Portlet WindowStates 675
ICEfaces Portlets and ConcurrentDOM Views 675
ICEfaces 1.xExtended
Request Scope
675ICEfaces
Ajax
Push andInter-PortletCommunication 676ICEfaces Themes and PortalThemes 679
ICEfaces Themesand
Liferay
Themes 680ICEfaces
Ajax
Bridge
andLiferay
Portal 681ICEfaces Portletsand
Liferay Request
Attributes 682PortletFaces 682
Downloading
PortletFaces 683PortletFacesContext 684
PortletFaces
Tags
685PortletFacesand PortletPreferences 686
PortletFaces
Expression Language
Additions 687PortletFaces and Localization 689