• No results found

JavaServer Faces 2.0: The Complete Reference

N/A
N/A
Protected

Academic year: 2021

Share "JavaServer Faces 2.0: The Complete Reference"

Copied!
14
0
0

Loading.... (view fulltext now)

Full text

(1)

JavaServer

Faces

2.0:

The

Complete

Reference

TIB/UB Hannover 89 133 219 50X

(2)

Contents

Acknowledgments

xxiii

Introduction

, xxv

Part §

The JavaServer

Faces Framework

1 Introductionto

JavaServer

Faces 3

What Is

JavaServer

Faces? 3

The

History

of

JavaServer

Faces . 4

TheCommon

Gateway

Interface , 4

TheServlet API

5

JavaServer Pages

5

Apache

Struts 6

The

Spring

Framework and

Spring

MVC 6

The Birth of

JavaServer

Faces 6

The

JavaServer

Faces

Design

Goals 7

JSF

Application

Architecture 9

The

JSF

Request

Processing Lifecycle

. 10

The

JSF Navigation

Model 12

2

Building

a

Simple

JavaServer

Faces

Application

. 15

Application

Overview 15

The

JSFReg Application

Files 16

The

JSF

Software Stack 17

Assembling

the

JSFReg Application

18

The

Configuration

File 19

TheFacelets

Pages

20

Building

and

Running

the

Application

30

Deploying

and

Running

the

Application

32

Reviewing

the

Key

Portionsof the

Application

32

3 The

JavaServer

Faces

Request Processing Lifecycle

35

A

High-Level

Overview of the

JSF

Request Processing Lifecycle

35

What

Exactly

Doesthe

Request Processing Lifecycle

Do? 36 HowDoes It DifferfromOtherWeb

Technologies?

36 Automatic Server-SideView

Management

and

Synchronization

... 37

The

Request Processing Lifecycle

Phases .. 38

Observing

the

Request Processing Lifecycle

in Action 46 Advanced

Topics

Relatedtothe

Request Processing Lifecycle

... 50

Using

the immediate Attribute 50

(3)

X JavaServer Faces 2.0: The

Complete

Reference

PhaseListeners 52

Exception

Handler 52

Lifecycle

Concepts

toRemember 53

4 TheFacelets View Declaration

Language

55

ThePower of

Templating

in Faces 56

Similarities and Differences Between

JSP

and Facelets 57

Templating

with Facelets 58

Guideto Facelets

Templating

Tags

62

uixomposition

62 ukdecorate 62 ukdefine 62 ukinserl 62 ui:include 64

uiparam

65

Guideto

Nontemplating

Facelets

Tags

65

ukcomponent

65

ui:fragment

65

ui:remove 65

ukdebug

66

5

Managed

Beans and the

JSF

Expression Language

67

What Are

Managed

Beans? 68

A

Simple Managed

Bean

Example

68

Initializing Managed

Bean

Properties

70

Declaring

Lists and

Maps

Directly

as

Managed

Beans 78

Managed

Bean

Interdependence

78

Setting

Managed

Properties

Using

EL 80

Controlling Managed

Bean Life

Spans

81

The

JSF

Expression

Language

84

Important Expression Languages

Changes

Between

JSF

1.1 and

JSF

1.2 84

Unified EL

Concepts

86

Value

Expressions

87

Expression Operators

93

Method

Expressions

94

Web

Application Development

Details on

Managed

Beans 97

HowtoAccess

Managed

Beans

Programmatically

98

Using Managed

Beansas

Backing

Beansfor

JSF

Pages

99

6 The

Navigation

Model 103

Using Implicit Navigation

103

Overview of the

JSF Navigation System

106

Recalling

MVC—The Controller 107

The

NavigationHandler—Behind

the Scenes 107

(4)

Contents

xi

Building

Navigation

Rules 109

A Static

Navigation

Example

Ill

A

Dynamic Navigation Example

112

More

Sophisticated

Navigation

Examples

116

Using

Wildcards 116

Using

Conditional

Navigation

117

Using

Redirects 118

XML

Configuration

forView

Parameters

132

Using JSF Components

on a Servlet Error

Page

133

7 The User Interface

Component

Model 135

WhatAre UI

Components?

135

TheRise of

Component-Based

Web

Development

136

The Goal of

JavaServer

Faces UI

Components

138

Introducing

the

JSF

UI

Component

Architecture 138

The UI

Component

Tree

(View)

143

The UI

Component

and ItsAssociated

"Moving

Parts" 145

Component

Resources 147

UI

Components

andFacelets 147

Accessing

UI

Components Programmatically

147

Helpful

Advicefor

Binding

UI

Components

in

JSF

Views 151

8

Converting

and

Validating

Data 155

SomeValidation andConversion

Examples

156

Conversion andValidation Under the Covers 158

The FacesConverter

System

162

DateTimeConverter 163

NumberConverter 164

Associating

aConverter witha

UlComponent

Instance 164

The Lifetime ofaConverter 170

Custom Converters 170

The Faces Validation

System

175

LongRangeValidator

177

DoubleRangeValidator

177

LengthValidator

177

The

"required" Facility

and the

RequiredValidator

178

RegExValidator

179

BeanValidator 179

How toAssociateaValidator witha

UlComponent

Instance 179

Using Markup

toAssociateaValidator with

a

UlComponent

Instance 180

Using Markup

and the validator AttributetoAssociate

aValidator witha

UlComponent

Instance 181

Programmatically Associating

a Validator with

(5)

Xlj

JavaServer Faces 2.0: The

Complete

Reference

The Lifetimeofa Validator 183

Custom Validators 183

Using

Bean Validationfrom

JSF

185

WhatIsBean Validation? 185

Differences Between

JSF

Validationand BeanValidation 186

Details on

Using

Bean Validation from

JSF

187

Validating

JSF

Managed

Bean

Properties

with Bean Validation .... 189

Tie It All

Together: Messages

ina View 190

FacesMessage-Related

MethodsonFacesContext 190

The UIViewRoot and ItsLocale

Property

192

When and How

FacesMessage

Instances

AreCreated and Addedto theFacesContext 192

How

FacesMessages

AreRendered 193

Messages

and Bean Validation 196

9 The

JSF

EventModel 199

A

High-Level

Overview of the

JSF

Event Model 199

Some Event

Examples

200

How

JSF

Events Work 203

The Faces Event ListenerInterfacesand EventClasses 204

When AreFacesEventsProcessed? 205

Application

Events 209

The

Anatomy

ofaValue

Change

Event 211

Writing

Custom Action and Value

Change

Listeners 212

More Faces Event

Examples

215

Using

aValue

Change

Event to Auto-FillFields 215

Extending

the Value

Change

Example

219

Working

with PhaseEvents and Listeners 221

Using

aPhaseListener toObserve the Faces

Lifecycle

in Action .. . 221

Working

with

SystemEvents

and Listeners 224

How

SystemEvents

Are Published 227

Howto Subscribe to

SystemEvents

227

General Rules for

Creating

Custom

Application

Events and Listeners .... 229

Creating

Custom

SystemEvent

and

ComponentSystemEvent

Classes 230

Part ii

Extending

JavaServer Faces

10

Applying JSF: Introducing

the VirtualTrainer

Application

235

A

Quick

Tourof the VirtualTrainer

Application

236

Registering

and

Logging

In to theVirtual Trainer

Application

236

Creating

aNew

Training

Event WorkoutPlan 237

Choosing

Your Trainer 239

ActionsAvailable

Only

to Trainers 239

The VirtualTrainer

Application Requirements

243

(6)

Contents

xiii

Facelet

Pages

244

Pages

inthe Web

Application

Root 244

Pages

in the

/user

Directory

244

Pages

in the

/trainer

Directory

245

Pages

in the

/

resources

Directory

245

Backing

Beans , 246

Persistence and Transaction

Architecture

248

Navigation

Concerns 252

Creating

a

Simple

Authentication

System

255

Revisiting

JSFReg:

Building

the

Registration System

259

Building

the Core

Pages

ofthe Virtual Trainer

Application

263

Creating

the

allEvents.xhtml

Page

263

The TrainerVersion of

editTrainingEvent.xhtml

266

Creating

the viewTrainees.xhtml

and

viewTrainingSessionsForUser.xhtml Pages

269

The

UserRegistry

and

EventRegistry

272

Accessing

and

Initializing

the

UserRegistry

Instance 272

Reading

and

Writing

User Instances 273

Reading

and

Writing TrainingSession

Instances 275

Accessing

and

Initializing

the

EventRegistry

Instance 277

Reading

and

Writing

Event Instances 278

JPA

and the

Entity

Classesin Virtual Trainer 280

JPA

XML

Configuration

File:

persistence.xml

281

A Custom

ExceptionHandler

Example

282

Internationalizing

the VirtualTrainer

Application

284

Localization 285

Final CommentsonVirtual Trainer 294

11

Building

Custom UI

Components

295

Deciding

Whento Build aCustom UI

Component

295

WhatAre UI

Components?

296

A

Simple

JSFU1

Component

297

The Code Behind the

Markup

of This

Simple

JSF

UI

Component

299

IntroductiontoResource Libraries 300

Adding

Behaviortoa

Composite Component

301

A First Look into the Details of

Composite Components

303

The

#{cc)

Implicit Object

305

ThePartsofaUI

Component

306

A

Noncomposite

JSF

Custom

UlComponent

307

Building

theHtmlHelloWorld

Example

307

AHelloWorld UI

Component

That

Accepts

Form

Input

312

A

JSF

Stock

Quote

Component

314

State

Management

with Custom

Components

316

Writing

toa

StateHelper

317

Reading

froma

StateHelper

318

(7)

Xiv Ja vaSe r v e r Faces 2.0: The

Complete

Reference

Extracting Rendering

Code into a Renderer 318

Creating

a CustomFacelet

Tag Library TagHandler

320

Using

a RenderKit to

Support Multiple

Client Device

Types

322

Advanced

Composite Component Development

330

Creating

a

Backing

Class for

<vt:loginPanel>

330

Composite Component

Feature Review 335

Packaging

JSF

Components

into aSelf-Contained

Jar

335

Packaging

a

Composite Component

intoa

Jar

336

Packaging

a

Composite

Component

Facelet File 336

Declaring

aCustom

Namespace

URL for

a

Composite Component Library

336

Packaging Backing

Classes for a

Composite

Component

337

Packaging

a

Noncomposite

Component

intoa

Jar

337

How the

JSF

RuntimeLoads

faces-config.xml

Files 337

How the

JSP

Runtime Loads T LD Files 338

12 JSF and

Aj

ax 339

Ajax

Overview 339

A

Simple

Ajax

Example

from

JSFReg

341

Ajax

JSFReg

Behind theScenes 343

The

<f:ajax> Tag

and ItsAttributes 349

The Standard

JavaScript

Resource 356

Advanced

Topics

on

JSF

and

Ajax

357

13

Building

Non-UI Custom

Components

359

Non-UICustom

Components

and Decorationin

JSF

359

Wrapper

Classes 362

Non-View Custom

Components Explained

363

PhaseListener 363

Interfaceto

Implement

363

Registering

aPhaseListener 364

Converter and Validator 364

Interfaces to

Implement

364

Registering

a ConverterorValidator 365

ViewHandler 365

AbstractClasstoExtend 365

Registering

aViewHandler 365

VariableResolverand

PropertyResolver

366

Abstract Classes toExtend 367

Registering

aVariableResolveror

PropertyResolver

368

ELResolver(JSF1.2)

369

TheELResolver Chain of

Responsibility

369

Abstract ClasstoExtend 372

(8)

Contents XV

NavigationHandler

378

AbstractClass toExtend 378

Registering

a

NavigationHandler

or

ConfigurableNavigationHandler

379 ActionListener 379 Interface to

Implement

380

Registering

anActionListener 380

StateManager

380

Abstract Classto Extend in

JSF

1.1 and1.0 380

AbstractClassto Extend in

JSF

1.2 382

Registering

a

StateManager

382 RenderKit 382 Factories in

JSF

383

Registering

a

Factory

384

RenderKitFactory

386

ExceptionHandlerFactory

388

FacesContextFactory

388

ExternalContextFactory

389

LifecycleFactory

390

PartialViewContextFactory

391

ViewDeclarationLanguageFactory

391

VisitContextFactory

392

Application Factory

393

Additional

Non-UIComponent

Topics

396

Telling

the

JSF

Runtime Where You Are

in theSoftware

Development Lifecycle:

ProjectStage

396

Custom

Scopes

397

14

Securing

JavaServer

Faces

Applications

399

Aspects

and

Implementation

of Web

Application Security

399

Container-Managed Security

400

Container-Managed

Authentication 400

BasicAuthentication and the

Concept

ofa "Realm" 401

Form-Based Authentication 402

Certificate Authentication 405

Container-Managed

Authorization and the

Concept

of Roles 407

Container-Managed

Data

Security

408

A Small

Security Improvement

inthe Virtual Trainer 410

Application-Managed

Security

with

JavaServer

Faces 411

Leveraging

J

AAS froma

JSF

Application

411

(9)

Xvi

JavaServer Faces 2.0: The

Complete

Reference

Part II!

JavaServer

Faces

Tools and Libraries

15

Configuring

JavaServer

Faces

Applications

423

Understanding

XML Schemas 425

Understanding

How

Configuration

FilesAreProcessed 425

Ordering

of

faces-config.xml

Files 426

How the

JSF

Runtime ScansClasses for

Configuration

Annotations 427

TheFaces

Configuration

Elements 427

The

absolute-ordering

Element 437

The action-listener Element 437

The

after

Element 438

The

application

Element 439

The

application-factory

Element 440

The 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 449

The

component

Element 450

The

component-class

Element 451

The

component-family

Element 451

The

component-type

Element 452

The 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 460

The

external-context-factory

Element 461 The

faces-config

Element 462 The

faces-context-factory

Element 463

ThefacetElement 463

The facet-nameElement 465

(10)

Contents

xvii

The from-action Element 466

The from-outcome Element 467

Thefrom-view-id Element 467

The if Element 468

The

key

Element 469

The

key-class

Element 470 The

lifecycle

Element 471 The

lifecycle-factory

Element 471

Thelist-entries Element 472

The

locale-config

Element 473

The

managed-bean

Element 474

The

managed-bean-class

Element 475

The

managed-bean-name

Element 475

The

managed-bean-scope

Element 476

The

managed-property

Element 477

The

map-entries

Element 479

The

map-entry

Element 480

The

message-bundle

Element 481

ThenameElement 482

The

navigation-case

Element 483

The

navigation-handler

Element 484

The

navigation-rule

Element 485

Thenull-value Element 486

The

ordering

Element 488

Theothers Element 488

The

partial-view-context-factory

Element 489

The

phase-listener

Element 490

The

property

Element 491

The

property-class

Element 492

The

property-name

Element 493

The

property-resolver

Element 494

The redirect Element 494

The

referenced-bean

Element 495

The

referenced-bean-class

Element 496

The referenced-bean-name Element 497

The render-kit Element 498

The render-kit-classElement 499

The

render-kit-factory

Element 499

The render-kit-idElement 500

TherendererElement 501

Therenderer-classElement 502

The

renderer-type

Element 503

Theresource-bundleElement 503

(11)

XVlii

JavaServer Faces 2.0: The

Complete

Reference

The source-classElement 504

The

state-manager

Element 505

The

suggested-value

Element 506

The

supported-locale

Element 507

The

system-event-class

Element 508

The

system-event-listener

Element 509

The

system-event-listener-class

Element 510

The

tag-handler-delegate-factory

Element 510

The 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 518

Theview-handler Element 519

The

view-param

Element 520

The

visit-context-factory

Element 521

ExtensionElements 521

Metadata Elements 523

16 The Standard

JSF Component Library

525

ABrief Review of

JSF, Facelets,

and

JSP

Tag

Nomenclature 525

Acquiring

and

Installing

the Standard Libraries 526

What You Get

(Binary)

527

What You Get

(Source)

527

The

Tag

Library

Reference 527

TheStandard Core

Library

527

The hactionListener

Tag

530

The

f:ajax

Tag (2.0)

531

The f:attribute

Tag

533

The fxonvertDateTime

Tag

533

The fxonvertNumber

Tag

535

The f:converter

Tag

537

The f:event

Tag (2.0)

538

The f:facet

Tag

538

The hloadBundle

Tag

539

The ^metadata

Tag (2.0)

540

The

f:param

Tag

540

The

f:phaseListener

Tag

(1.2,2.0)

541

The f:selectltem

Tag

541

The hselectltems

Tag

542

(12)

Contents

The f:subview

Tag

545

Thef:validateBeanTag(2.0)

547

The

f:validateDoubleRange Tag

549

The

f:validateLength Tag

550

The

f:validateLongRange Tag

551

The

f:validateRegex Tag (2.0)

552

The

f:validateRequired Tag (2.0)

552

The f:validator

Tag

553

The

f:valueChangeListener

Tag

554

Thef:verbatim

Tag

555

Thef:view

Tag

556

The f:viewParam

Tag (2.0)

557

The Standard HTML

Library

559

Theh:bodyTag(2.0)

562

The h:button

Tag

(2.0)

563

The h:column

Tag

565

The hxommandButton

Tag

567

The hxommandLink

Tag

570

The h:dataTable

Tag

573

Theh:formTag

576

The

h:graphiclmage

Tag

578

Theh:headTag(2.0)

580

The

h:inputHidden Tag

581

The

h:inputSecret

Tag

582

The

h:inputText

Tag

585

The

h:inputTextarea Tag

588

The Mink

Tag (2.0)

591

The

h:message Tag

594

Themessages

Component

596

Theh.-outputFormatTag

597

The

h:outputLabel Tag

598

The

h:outputLink

Tag

600

The

h:outputScript Tag (2.0)

602

The

h:outputStylesheet Tag (2.0)

603

The

h:outputText Tag

605

The

h:panelGrid Tag

606

The

h:panelGroup Tag

608

The hrselectBooleanCheckbox

Tag

609

The

h:selectManyCheckbox Tag

612

The

h:selectManyListbox Tag

615

The

h:selectManyMenu Tag

618

The h:selectOneListbox

Tag

621

The kselectOneMenu

Tag

624

(13)

XX lavaServer Faces

2.0:

The

Complete

Reference

The Standard Facelets

Templating

Library

(2.0)

631

Example

Website

Project

632

The

uixomponent

Tag

(2.0)

636

The ui

composition

Tag (2.0)

637

The

ui:debug Tag

(2.0)

637

The ui:decorate

Tag

(2.0)

638

The ui:define

Tag

(2.0)

639

Theui:fragmentTag(2.0)

639

The uidnclude

Tag

(2.0)

640

The ui:insert

Tag

(2.0)

640

The

uiparam Tag

(2.0)

641

The ui.'remove

Tag

(2.0)

641

The

ui:repeat Tag

(2.0)

642

The Standard Facelets

Composite Component Library

(2.0)

643

Example Project

645

The ccactionSource

Tag

(2.0)

650

The ccattribute

Tag

(2.0)

651

The cceditableValueHolder

Tag

(2.0)

652

Theccextension

Tag (2.0)

653

TheccfacetTag (2.0)

654

The

complementation Tag

(2.0)

654

Thecc.insertChildren

Tag

(2.0)

655

The ccinsertFacet

Tag

(2.0)

655

The ccinterface

Tag (2.0)

656

ThecerenderFacet

Tag (2.0)

657

The ccvalueHolder

Tag

(2.0)

658

A

JSFPortlets

659

Overview of Portlet 1.0 and2.0 659

Portlet

Lifecycle

659

Portlet Modes 660

Portlet Window States 661

Portlet Preferences 661

Inter-Portlet Communication 662

JSF

Portlet

Development

663

JSF

Portlet

Bridges

663

JSF

Portlet View Handlers 667

JSF

ExternalContext and thePortlet API 668

JSF

and Portlet Preferences 668

JSF

and Inter-Portlet Communication 670

ICEfacesPortlet

Development

672

ICEfaces

Ajax

with Partial Submit 672

ICEfaces Direct-to-DOM RenderKit 673

The

ice:portlet Tag

673

(14)

Contents

xxi

ICEfaces 1.xD2DFaceletViewHandler 674

ICEfaces 1.x and Portlet WindowStates 675

ICEfaces Portlets and ConcurrentDOM Views 675

ICEfaces 1.xExtended

Request Scope

675

ICEfaces

Ajax

Push andInter-PortletCommunication 676

ICEfaces Themes and PortalThemes 679

ICEfaces Themesand

Liferay

Themes 680

ICEfaces

Ajax

Bridge

and

Liferay

Portal 681

ICEfaces Portletsand

Liferay Request

Attributes 682

PortletFaces 682

Downloading

PortletFaces 683

PortletFacesContext 684

PortletFaces

Tags

685

PortletFacesand PortletPreferences 686

PortletFaces

Expression Language

Additions 687

PortletFaces and Localization 689

Liferay

Language

Portlet

Integration

690

Improved Integration

Between

Liferay

and ICEfaces 1.x 690

References

Related documents

De tal manera existe una estrecha relación entre lo que entendemos por memoria social (Fentress. y Wickman 2003) y patrimonio; habida cuenta de que la memoria social

Važnost trgovine između država članica EU očituje se u tome da je trgovina robom (izvoz i uvoz zajedno) na unutarnjem tržištu bila veća od trgovine izvan Europske

Java Enterprise Edition, Sun Java System Application Server, Java Servlet API, JavaServer Pages, JavaServer Faces, Enterprise Java Beans, Java Persistence API, Java Web

Java Web Technologies, Servlets, JavaServer Pages, JavaServer Faces, Web Technologies in Netbeans, Creating and Running a Web Application in Netbean, Examining a JSP File, Examining

The Oracle Product Master Data Management Integration Pack, offers a pre-built integration process that seamlessly integrates Oracle Product Data Hub to Siebel

3. Care Coordinator initiates registration of patient from Home Telehealth service using VistA a) VistA sends HL7 sign-up message with patient identification to vendor system. b)

And even when all goods positively valued are sold in both strategies (customized bundling and individual sale), customized bundling will yield higher profits as long as a is

We show that in the quantity-setting case the optimal generalized welfare function assigned to the public management overvalues the public firm’s and the rival’s profits, while