JavaServer Faces in Action

This document was uploaded by one of our users. The uploader already confirmed that they had the permission to publish it. If you are author/publisher or own the copyright of this documents, please report to us by using this DMCA report form.

Simply click on the Download Book button.

Yes, Book downloads on Ebookily are 100% Free.

Sometimes the book is free on Amazon As well, so go ahead and hit "Search on Amazon"

Helping front-end developers, back-end developers, and architects understand how they can get the most out of JavaServer Faces (JSF), this guide to the new official standard for simplifying Java web development explains what JSF is, how it works, and how it relates to other frameworks and technologies like Struts, Servlets, Portlets, JSP, and JSTL. Also provided is coverage of all the standard components, renderers, converters, and validators, along with advice on how to use them to create solid applications. The building of complete JSF applications is demonstrated with an in-depth case study covering complex user interface layouts, prototyping, and integrating templates with back-end model objects. Also covered are advanced techniques like internationalization, integration with Struts, and extending JSF with custom components, renderers, converters, and validators.

Author(s): Howard M. Lewis Ship
Series: In Action series
Edition: illustrated edition
Publisher: Manning Publications
Year: 2004

Language: English
Pages: 1073

TeamLiB......Page 1
Cover......Page 2
Foreword......Page 22
Preface......Page 24
Aacknowledgments......Page 26
About this book......Page 28
How to use this book......Page 29
Conventions......Page 30
Source code and the online extension......Page 32
About the author......Page 33
About the title......Page 34
About the cover illustration......Page 35
Part 1 - Exploring JavaServer Faces......Page 36
Introducing JavaServer Faces......Page 38
1.1 It’s a RAD-ical world......Page 39
1.1.1 So, what is JavaServer Faces?......Page 40
1.2 The technology under the hood......Page 45
1.2.1 Hypertext Transfer Protocol (HTTP)......Page 46
1.2.2 Servlets......Page 47
1.2.3 Portlets......Page 48
1.2.4 JavaBeans......Page 49
1.2.5 JSP and other display technologies......Page 50
1.3.1 Why do we need frameworks?......Page 51
1.3.2 She’s a Model 2......Page 52
1.3.3 JSF, Struts, and other frameworks......Page 53
1.4 Components everywhere......Page 54
1.5 Hello, world!......Page 57
1.5.1 Dissecting hello.jsp......Page 59
1.5.2 Dissecting goodbye.jsp......Page 66
1.5.3 Examining the HelloBean class......Page 67
1.5.4 Configuration with faces-config.xml......Page 69
1.5.5 Configuration with web.xml......Page 71
1.6 Summary......Page 72
JSF fundamentals......Page 73
2.1 The key pieces of the pie......Page 74
2.1.1 User interface components......Page 76
2.1.2 Renderers......Page 78
2.1.3 Validators......Page 79
2.1.4 Backing beans......Page 80
2.1.5 Converters......Page 83
2.1.6 Events and listeners......Page 84
2.1.7 Messages......Page 90
2.1.8 Navigation......Page 91
2.2 The Request Processing Lifecycle......Page 92
2.2.1 Phase 1: Restore View......Page 96
2.2.2 Phase 2: Apply Request Values......Page 98
2.2.3 Phase 3: Process Validations......Page 100
2.2.5 Phase 5: Invoke Application......Page 101
2.2.6 Phase 6: Render Response......Page 103
2.3 Understanding component and client identifiers......Page 104
2.3.1 Naming containers......Page 107
2.3.2 Referencing identifiers......Page 108
2.4 Exploring the JSF expression language......Page 111
2.4.1 Understanding scoped variables......Page 115
2.4.2 Using implicit variables......Page 116
2.4.3 Using the EL with components......Page 118
2.5 Summary......Page 121
Warming up: getting around JSF......Page 123
3.1.2 Choosing a JSF implementation......Page 124
3.1.3 Directory structure......Page 125
3.1.4 Configuration......Page 127
3.2 The role of JSP......Page 137
3.2.1 Using JSP includes......Page 138
3.2.2 Using JSF with JSTL and other JSP custom tags......Page 139
3.3 Creating and initializing beans......Page 145
3.3.1 Declaring managed beans......Page 148
3.3.2 Declaring Lists and Maps as managed beans......Page 158
3.3.3 Setting values with value-binding expressions......Page 160
3.4 Navigating the sea of pages......Page 164
3.5 Summary......Page 171
Getting started with the standard components......Page 172
4.1 It’s all in the components......Page 173
4.1.1 Using HTML attributes......Page 177
4.1.2 Understanding facets......Page 178
4.1.3 The power of tools......Page 180
4.2 Common component properties......Page 183
4.3 Controlling the page with UIViewRoot......Page 184
4.4 Setting component parameters with UIParameter......Page 186
4.5.1 Displaying ordinary text with HtmlOutputText......Page 188
4.5.2 Using UIOutput with the tag......Page 190
4.5.3 Creating input labels with HtmlOutputLabel......Page 193
4.5.4 Using HtmlOutputFormat for parameterized text......Page 195
4.5.5 Displaying hyperlinks with HtmlOutputLink......Page 200
4.6 Displaying images with HtmlGraphicImage......Page 202
4.7 Displaying component messages with HtmlMessage......Page 204
4.8 Displaying application messages with HtmlMessages......Page 207
4.9.1 Grouping components with HtmlPanelGroup......Page 211
4.9.2 Creating tables with HtmlPanelGrid......Page 213
4.10 Summary......Page 219
Using the input and data table components......Page 220
5.1 Registering event listeners......Page 221
5.1.2 Declaring action listeners......Page 222
5.2 Common component properties......Page 224
5.3 Handling forms with HtmlForm......Page 225
5.4 Handling basic user input......Page 227
5.4.1 Declaring basic text fields with HtmlInputText......Page 228
5.4.2 Using HtmlInputTextarea for memo fields......Page 229
5.4.3 Displaying password fields with HtmlInputSecret......Page 230
5.4.4 Declaring hidden fields with HtmlInputHidden......Page 232
5.5 Using HtmlSelectBooleanCheckbox for checkboxes......Page 233
5.6 Defining item lists......Page 234
5.6.1 Using UISelectItem for single items......Page 235
5.6.2 Using UISelectItems for multiple items......Page 238
5.7.1 Using HtmlSelectManyCheckbox for checkbox groups......Page 240
5.7.2 Displaying listboxes with HtmlSelectManyListbox......Page 243
5.7.3 Using HtmlSelectManyMenu for single-item listboxes......Page 245
5.8.1 Using HtmlSelectOneRadio for radio button groups......Page 247
5.8.2 Using single-select listboxes with HtmlSelectOneListbox......Page 250
5.8.3 Declaring combo boxes with HtmlSelectOneMenu......Page 252
5.9.1 Declaring buttons with HtmlCommandButton......Page 254
5.9.2 Creating an action link with HtmlCommandLink......Page 256
5.10 Displaying data sets with HtmlDataTable......Page 258
5.11 Summary......Page 268
Internationalization, validators, and converters......Page 269
6.1 Internationalization and localization......Page 270
6.1.1 Looking into locales......Page 271
6.1.2 Creating resource bundles......Page 273
6.1.3 Using resource bundles with components......Page 276
6.1.4 Internationalizing text from back-end code......Page 279
6.2.1 Using validator methods......Page 280
6.2.2 Using validators......Page 281
6.2.3 Using the standard validators......Page 282
6.3 Type conversion and formatting......Page 286
6.3.1 Using converters......Page 289
6.3.2 Working with the standard converters......Page 290
6.4 Customizing application messages......Page 304
6.5 Summary......Page 308
Part 2 - Building user interfaces......Page 310
Introducing ProjectTrack......Page 312
7.1 Requirements......Page 313
7.2 The conceptual model......Page 316
7.3 User interface......Page 318
7.4 Development team......Page 319
7.5 Summary......Page 321
Developing a user interface without Java code: the Login page......Page 322
8.1.1 Setting up web.xml......Page 324
8.1.2 Setting up faces-config.xml......Page 325
8.2 Creating the Login page......Page 326
8.2.1 Starting with HtmlGraphicImage and HtmlOutputText components......Page 327
8.2.2 Adding a form......Page 330
8.3 Sprucing things up......Page 335
8.3.2 Integrating with JavaScript......Page 336
8.3.3 Adding Cascading Style Sheets......Page 338
8.4 Adding validators......Page 339
8.4.1 Customizing validation messages......Page 342
8.5 Improving layout with HtmlPanelGrid......Page 343
8.6 Summary......Page 349
Developing a user interface without Java code: the other pages......Page 351
9.1 Building the header with a custom component......Page 352
9.1.1 Using a custom toolbar component......Page 356
9.1.2 Configuring the navigation rule......Page 358
9.2 Prototyping data tables with panels......Page 359
9.2.1 The Inbox page......Page 360
9.2.2 Configuring the navigation rule......Page 364
9.2.4 Configuring the navigation rule......Page 365
9.3.1 The Approve a Project page......Page 366
9.3.2 Configuring the navigation rule......Page 372
9.3.3 The Reject a Project page......Page 373
9.3.5 The Create a Project page......Page 376
9.4 The Project Details page......Page 382
9.4.1 Configuring the navigation rule......Page 386
9.5 Summary......Page 388
Integrating application functionality......Page 389
10.1 Understanding JSF development approaches......Page 390
10.2 Exploring the application environment......Page 392
10.4 The Login page......Page 395
10.4.1 Updating the navigation rule......Page 399
10.5 The header......Page 400
10.5.1 Updating the navigation rule......Page 404
10.6.1 The Inbox page......Page 405
10.6.2 The Show All page......Page 413
10.7.1 Updating the includes......Page 414
10.7.2 The Approve a Project page......Page 417
10.7.3 The Reject a Project page......Page 420
10.7.4 The Create a Project page......Page 421
10.8 The Project Details page......Page 425
10.8.1 Updating the navigation rule......Page 430
10.9 Adding an error page......Page 431
10.9.2 Updating the navigation rule......Page 432
10.10.1 Externalizing text into the resource bundle......Page 433
10.10.2 Internationalizing the header......Page 435
10.10.3 Localizing for Russian......Page 437
10.11 Summary......Page 439
Part 3 - Developing application logic......Page 442
The JSF environment......Page 444
11.1 From servlets to JSF......Page 445
11.2.1 Application......Page 448
11.2.2 Evaluation expressions......Page 452
11.3 It’s all in the context......Page 454
11.3.1 FacesContext......Page 455
11.3.2 FacesMessage......Page 457
11.3.3 ExternalContext......Page 459
11.4 Event handling......Page 463
11.4.1 FacesEvent......Page 465
11.4.2 Handling action events......Page 467
11.4.3 Handling value-change events......Page 469
11.4.4 Handling phase events......Page 470
11.5 Components revisited......Page 473
11.5.1 UIComponent......Page 477
11.5.2 UIViewRoot......Page 481
11.5.3 ValueHolder......Page 484
11.5.4 EditableValueHolder......Page 486
11.5.5 SelectItem and SelectItemGroup model beans......Page 488
11.6 Summary......Page 490
Building an application: design issues and foundation classes......Page 491
12.1 Layers of the pie......Page 492
12.2 Roasting the beans......Page 495
12.2.1 The importance of toString......Page 496
12.2.3 It’s all in the properties......Page 497
12.2.4 Exposing beans......Page 507
12.3 Exploring the business layer and data layers......Page 508
12.4 Developing the application layer......Page 511
12.4.1 Handling constants......Page 513
12.4.2 Organizing utility methods......Page 515
12.4.3 Initializing singletons......Page 517
12.4.4 Adapting business objects......Page 519
12.5 Writing a visit object for session state......Page 526
12.6 Developing a base backing bean class......Page 529
12.7 Summary......Page 533
Building an application: backing beans, security, and internationalization......Page 534
13.1 Writing backing beans......Page 535
13.1.2 Handling errors......Page 536
13.1.3 Performing authentication......Page 540
13.1.4 Listing projects with UIData and parameterizing listeners......Page 546
13.1.5 Updating projects......Page 557
13.1.6 Creating new projects......Page 563
13.1.7 Paging through the project history with UIData......Page 569
13.1.8 Working with JDBC ResultSets and UIData......Page 575
13.2 Adding security......Page 580
13.2.1 Container-based vs. custom security......Page 581
13.2.2 Using custom security......Page 582
13.3 Supporting internationalization in code......Page 586
13.3.1 Internationalizing text with resource bundles......Page 587
13.3.2 Internationalizing messages......Page 592
13.4.1 Accessing the business layer......Page 597
13.4.2 Organizing beans by function......Page 598
13.4.3 Action methods implemented by backing beans......Page 599
13.4.4 Initializing backing bean properties with the Managed Bean Creation facility......Page 600
13.5 Summary......Page 601
Integrating JSF with Struts and existing applications......Page 603
14.2 When to use JSF with other frameworks......Page 604
14.3 The many faces of requests and responses......Page 606
14.4 Integrating JSF with Struts applications......Page 607
14.4.1 First steps......Page 610
14.4.2 Migrating Struts JSP tags......Page 612
14.4.3 Using JSF action methods and managed beans......Page 632
14.4.4 Who’s controlling whom?......Page 634
14.5 Integrating JSF with non-Struts applications......Page 635
14.6 Summary......Page 636
Part 4 - Writing custom components, renderers, validators, and converters......Page 638
The JSF environment: a component developer’s perspective......Page 640
15.1 Three steps to UI extension nirvana......Page 641
15.2 Developing UI components......Page 642
15.2.1 Deciding when to write a UI component......Page 643
15.2.2 Classes and interfaces......Page 645
15.2.3 Event handling with method bindings......Page 658
15.2.4 Registration......Page 659
15.2.5 JSP integration......Page 662
15.3 Developing renderers......Page 671
15.3.1 Deciding when to write a renderer......Page 675
15.3.2 Renderer......Page 676
15.3.3 RenderKit......Page 678
15.3.4 Registration......Page 679
15.3.5 JSP integration......Page 682
15.4 Developing validators......Page 683
15.4.1 Validator......Page 684
15.4.2 Registration......Page 685
15.4.3 JSP integration......Page 687
15.5.1 Converter......Page 689
15.5.2 Registration......Page 692
15.5.3 JSP integration......Page 693
15.7 Packaging UI extensions......Page 695
15.8 Summary......Page 696
Using JSF without JSP......Page 700
A.2 Creating views with class-based pages......Page 701
A.3 Creating views with XUL......Page 705
A.4 Other options......Page 706
References......Page 710
A......Page 714
B......Page 716
C......Page 717
D......Page 718
F......Page 719
H......Page 720
I......Page 722
J......Page 723
L......Page 725
M......Page 726
O......Page 727
P......Page 728
R......Page 729
S......Page 730
U......Page 732
V......Page 735
W......Page 736
X......Page 737
Part 5 - Writing custom components, renderers, validators, and converters: examples......Page 738
UIInputDate: a simple input component......Page 740
16.1 Writing the UIInputDate class......Page 743
16.1.1 Encoding......Page 744
16.1.2 Decoding......Page 750
16.1.3 Implementing StateHolder methods......Page 752
16.3.1 Writing the JSP custom tag......Page 753
16.3.2 Validating the tag......Page 756
16.3.3 Adding the tag to the tag library......Page 757
16.4 Using the component......Page 759
16.5 Summary......Page 760
RolloverButton renderer: a renderer with JavaScript support......Page 762
17.1 Writing the RolloverButtonRenderer class......Page 764
17.1.1 Encoding......Page 766
17.1.2 Decoding......Page 770
17.1.3 Registering the renderer......Page 771
17.2 JSP Integration......Page 772
17.2.1 Writing the HtmlBaseTag class......Page 773
17.2.2 Writing the JSP custom tag......Page 776
17.2.3 Validating the tag......Page 779
17.2.4 Adding the tag to the tag library......Page 780
17.3 Using the renderer......Page 783
17.4.1 Developing the RolloverButtonDecoratorRenderer class......Page 785
17.5 Summary......Page 789
UIHeadlineViewer: a composite, data-aware component......Page 791
18.1 RSS and the Informa API......Page 793
18.2 Using UIData with Informa......Page 798
18.3 Subclassing DataModel......Page 800
18.4 Writing the UIHeadlineViewer class......Page 803
18.5 Registering the component......Page 815
18.6.1 Writing the JSP custom tag......Page 816
18.6.2 Adding the tag to the tag library......Page 822
18.7 Using the component......Page 824
18.8 Summary......Page 828
UINavigator: a model-driven toolbar component......Page 829
19.1 Writing the model classes......Page 831
19.2 Writing the UINavigator class......Page 836
19.2.1 Implementing ActionSource methods......Page 838
19.2.2 Overriding UIComponentBase methods......Page 841
19.2.3 Implementing StateHolder methods......Page 842
19.2.4 Developing NavigatorActionListener: a custom ActionListener......Page 844
19.3 Registering the component......Page 845
19.4.1 Encoding......Page 846
19.4.2 Decoding......Page 855
19.5 Registering the renderer......Page 856
19.6.1 Writing the Navigator_ToolbarTag component tag......Page 857
19.6.2 Writing the NavigatorItemTag tag handler......Page 861
19.6.3 Adding the tags to the tag library......Page 866
19.7 Using the component......Page 869
19.8 Summary......Page 873
Validator and converter examples......Page 874
20.2 Developing a validator......Page 875
20.2.1 Writing the RegularExpressionValidator class......Page 877
20.2.3 Integrating with JSP......Page 882
20.2.4 Using the validator......Page 887
20.4 Developing a converter......Page 889
20.4.1 Writing the UserConverter class......Page 891
20.4.2 Registering the converter......Page 900
20.4.3 JSP integration......Page 901
20.4.4 Using the converter......Page 905
20.5 Summary......Page 907
A survey of JSF IDEs and implementations......Page 908
B.1 Using JSF with Oracle JDeveloper......Page 909
B.1.2 What are ADF Faces Components?......Page 910
B.1.3 Exploring JDeveloper......Page 913
B.1.4 Building ProjectTrack’s Login page......Page 914
B.1.5 Wrapping up......Page 929
B.2 Using JSF with WebSphere Studio......Page 930
B.2.1 Exploring WebSphere Studio......Page 931
B.2.2 Building ProjectTrack’s Login page......Page 933
B.2.3 Wrapping up......Page 951
B.3.1 Using Java Studio Creator......Page 953
B.3.2 Building ProjectTrack’s Login page......Page 955
B.3.3 Wrapping up......Page 967
B.4 JSF implementations......Page 968
Extending the core JSF classes......Page 970
C.1 The classes behind the scenes......Page 971
C.2 Replacing or extending the pluggable classes......Page 975
C.2.1 Configuring a pluggable class......Page 977
C.2.2 Decorating a pluggable class......Page 978
C.2.3 Replacing a pluggable class......Page 982
JSF configuration......Page 993
D.1 Common attributes......Page 995
D.2.2 ......Page 996
D.2.3 ......Page 997
D.3.1 ......Page 998
D.3.2 ......Page 1000
D.3.3 ......Page 1003
D.3.4 ......Page 1004
D.4.1 ......Page 1005
D.4.2 ......Page 1006
D.4.4 ......Page 1008
D.5.1 ......Page 1009
D.5.2 ......Page 1010
Time zone, country, language, and currency codes......Page 1011
E.1 Time zone codes......Page 1012
E.2 Language codes......Page 1025
E.3 Country codes......Page 1029
E.4 Currency codes......Page 1037
References......Page 1046
A......Page 1050
B......Page 1052
C......Page 1053
D......Page 1054
F......Page 1055
H......Page 1056
I......Page 1058
J......Page 1059
L......Page 1061
M......Page 1062
O......Page 1063
P......Page 1064
R......Page 1065
S......Page 1066
U......Page 1068
V......Page 1071
W......Page 1072
X......Page 1073