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): Kito Mann
Series: In Action series
Publisher: Manning
Year: 2005

Language: English
Pages: 1073

foreword......Page 21
preface......Page 23
acknowledgments......Page 25
about this book......Page 27
How to use this book......Page 28
Conventions......Page 29
Source code and the online extension......Page 31
About the author......Page 32
About the title......Page 33
About the cover illustration......Page 34
Part 1 - Exploring JavaServer Faces......Page 35
Introducing JavaServer Faces......Page 37
1.1 It’s a RAD-ical world......Page 38
1.1.1 So, what is JavaServer Faces?......Page 39
1.2 The technology under the hood......Page 44
1.2.1 Hypertext Transfer Protocol (HTTP)......Page 45
1.2.2 Servlets......Page 46
1.2.3 Portlets......Page 47
1.2.4 JavaBeans......Page 48
1.2.5 JSP and other display technologies......Page 49
1.3.1 Why do we need frameworks?......Page 50
1.3.2 She’s a Model 2......Page 51
1.3.3 JSF, Struts, and other frameworks......Page 52
1.4 Components everywhere......Page 53
1.5 Hello, world!......Page 56
1.5.1 Dissecting hello.jsp......Page 58
1.5.2 Dissecting goodbye.jsp......Page 65
1.5.3 Examining the HelloBean class......Page 66
1.5.4 Configuration with faces-config.xml......Page 68
1.5.5 Configuration with web.xml......Page 70
1.6 Summary......Page 71
JSF fundamentals......Page 72
2.1 The key pieces of the pie......Page 73
2.1.1 User interface components......Page 75
2.1.2 Renderers......Page 77
2.1.3 Validators......Page 78
2.1.4 Backing beans......Page 79
2.1.5 Converters......Page 82
2.1.6 Events and listeners......Page 83
2.1.7 Messages......Page 89
2.1.8 Navigation......Page 90
2.2 The Request Processing Lifecycle......Page 91
2.2.1 Phase 1: Restore View......Page 95
2.2.2 Phase 2: Apply Request Values......Page 97
2.2.3 Phase 3: Process Validations......Page 99
2.2.5 Phase 5: Invoke Application......Page 100
2.2.6 Phase 6: Render Response......Page 102
2.3 Understanding component and client identifiers......Page 103
2.3.1 Naming containers......Page 106
2.3.2 Referencing identifiers......Page 107
2.4 Exploring the JSF expression language......Page 110
2.4.1 Understanding scoped variables......Page 114
2.4.2 Using implicit variables......Page 115
2.4.3 Using the EL with components......Page 117
2.5 Summary......Page 120
Warming up: getting around JSF......Page 122
3.1.2 Choosing a JSF implementation......Page 123
3.1.3 Directory structure......Page 124
3.1.4 Configuration......Page 126
3.2 The role of JSP......Page 136
3.2.1 Using JSP includes......Page 137
3.2.2 Using JSF with JSTL and other JSP custom tags......Page 138
3.3 Creating and initializing beans......Page 144
3.3.1 Declaring managed beans......Page 147
3.3.2 Declaring Lists and Maps as managed beans......Page 157
3.3.3 Setting values with value-binding expressions......Page 159
3.4 Navigating the sea of pages......Page 163
3.5 Summary......Page 170
Getting started with the standard components......Page 171
4.1 It’s all in the components......Page 172
4.1.1 Using HTML attributes......Page 176
4.1.2 Understanding facets......Page 177
4.1.3 The power of tools......Page 179
4.2 Common component properties......Page 182
4.3 Controlling the page with UIViewRoot......Page 183
4.4 Setting component parameters with UIParameter......Page 185
4.5.1 Displaying ordinary text with HtmlOutputText......Page 187
4.5.2 Using UIOutput with the tag......Page 189
4.5.3 Creating input labels with HtmlOutputLabel......Page 192
4.5.4 Using HtmlOutputFormat for parameterized text......Page 194
4.5.5 Displaying hyperlinks with HtmlOutputLink......Page 199
4.6 Displaying images with HtmlGraphicImage......Page 201
4.7 Displaying component messages with HtmlMessage......Page 203
4.8 Displaying application messages with HtmlMessages......Page 206
4.9.1 Grouping components with HtmlPanelGroup......Page 210
4.9.2 Creating tables with HtmlPanelGrid......Page 212
4.10 Summary......Page 218
Using the input and data table components......Page 219
5.1 Registering event listeners......Page 220
5.1.2 Declaring action listeners......Page 221
5.2 Common component properties......Page 223
5.3 Handling forms with HtmlForm......Page 224
5.4 Handling basic user input......Page 226
5.4.1 Declaring basic text fields with HtmlInputText......Page 227
5.4.2 Using HtmlInputTextarea for memo fields......Page 228
5.4.3 Displaying password fields with HtmlInputSecret......Page 229
5.4.4 Declaring hidden fields with HtmlInputHidden......Page 231
5.5 Using HtmlSelectBooleanCheckbox for checkboxes......Page 232
5.6 Defining item lists......Page 233
5.6.1 Using UISelectItem for single items......Page 234
5.6.2 Using UISelectItems for multiple items......Page 237
5.7.1 Using HtmlSelectManyCheckbox for checkbox groups......Page 239
5.7.2 Displaying listboxes with HtmlSelectManyListbox......Page 242
5.7.3 Using HtmlSelectManyMenu for single-item listboxes......Page 244
5.8.1 Using HtmlSelectOneRadio for radio button groups......Page 246
5.8.2 Using single-select listboxes with HtmlSelectOneListbox......Page 249
5.8.3 Declaring combo boxes with HtmlSelectOneMenu......Page 251
5.9.1 Declaring buttons with HtmlCommandButton......Page 253
5.9.2 Creating an action link with HtmlCommandLink......Page 255
5.10 Displaying data sets with HtmlDataTable......Page 257
5.11 Summary......Page 267
Internationalization, validators, and converters......Page 268
6.1 Internationalization and localization......Page 269
6.1.1 Looking into locales......Page 270
6.1.2 Creating resource bundles......Page 272
6.1.3 Using resource bundles with components......Page 275
6.1.4 Internationalizing text from back-end code......Page 278
6.2.1 Using validator methods......Page 279
6.2.2 Using validators......Page 280
6.2.3 Using the standard validators......Page 281
6.3 Type conversion and formatting......Page 285
6.3.1 Using converters......Page 288
6.3.2 Working with the standard converters......Page 289
6.4 Customizing application messages......Page 303
6.5 Summary......Page 307
Part 2 - Building user interfaces......Page 309
Introducing ProjectTrack......Page 311
7.1 Requirements......Page 312
7.2 The conceptual model......Page 315
7.3 User interface......Page 317
7.4 Development team......Page 318
7.5 Summary......Page 320
Developing a user interface without Java code: the Login page......Page 321
8.1.1 Setting up web.xml......Page 323
8.1.2 Setting up faces-config.xml......Page 324
8.2 Creating the Login page......Page 325
8.2.1 Starting with HtmlGraphicImage and HtmlOutputText components......Page 326
8.2.2 Adding a form......Page 329
8.3 Sprucing things up......Page 334
8.3.2 Integrating with JavaScript......Page 335
8.3.3 Adding Cascading Style Sheets......Page 337
8.4 Adding validators......Page 338
8.4.1 Customizing validation messages......Page 341
8.5 Improving layout with HtmlPanelGrid......Page 342
8.6 Summary......Page 348
Developing a user interface without Java code: the other pages......Page 350
9.1 Building the header with a custom component......Page 351
9.1.1 Using a custom toolbar component......Page 355
9.1.2 Configuring the navigation rule......Page 357
9.2 Prototyping data tables with panels......Page 358
9.2.1 The Inbox page......Page 359
9.2.2 Configuring the navigation rule......Page 363
9.2.4 Configuring the navigation rule......Page 364
9.3.1 The Approve a Project page......Page 365
9.3.2 Configuring the navigation rule......Page 371
9.3.3 The Reject a Project page......Page 372
9.3.5 The Create a Project page......Page 375
9.4 The Project Details page......Page 381
9.4.1 Configuring the navigation rule......Page 385
9.5 Summary......Page 387
Integrating application functionality......Page 388
10.1 Understanding JSF development approaches......Page 389
10.2 Exploring the application environment......Page 391
10.4 The Login page......Page 394
10.4.1 Updating the navigation rule......Page 398
10.5 The header......Page 399
10.5.1 Updating the navigation rule......Page 403
10.6.1 The Inbox page......Page 404
10.6.2 The Show All page......Page 412
10.7.1 Updating the includes......Page 413
10.7.2 The Approve a Project page......Page 416
10.7.3 The Reject a Project page......Page 419
10.7.4 The Create a Project page......Page 420
10.8 The Project Details page......Page 424
10.8.1 Updating the navigation rule......Page 429
10.9 Adding an error page......Page 430
10.9.2 Updating the navigation rule......Page 431
10.10.1 Externalizing text into the resource bundle......Page 432
10.10.2 Internationalizing the header......Page 434
10.10.3 Localizing for Russian......Page 436
10.11 Summary......Page 438
Part 3 - Developing application logic......Page 441
The JSF environment......Page 443
11.1 From servlets to JSF......Page 444
11.2.1 Application......Page 447
11.2.2 Evaluation expressions......Page 451
11.3 It’s all in the context......Page 453
11.3.1 FacesContext......Page 454
11.3.2 FacesMessage......Page 456
11.3.3 ExternalContext......Page 458
11.4 Event handling......Page 462
11.4.1 FacesEvent......Page 464
11.4.2 Handling action events......Page 466
11.4.3 Handling value-change events......Page 468
11.4.4 Handling phase events......Page 469
11.5 Components revisited......Page 472
11.5.1 UIComponent......Page 476
11.5.2 UIViewRoot......Page 480
11.5.3 ValueHolder......Page 483
11.5.4 EditableValueHolder......Page 485
11.5.5 SelectItem and SelectItemGroup model beans......Page 487
11.6 Summary......Page 489
Building an application: design issues and foundation classes......Page 490
12.1 Layers of the pie......Page 491
12.2 Roasting the beans......Page 494
12.2.1 The importance of toString......Page 495
12.2.3 It’s all in the properties......Page 496
12.2.4 Exposing beans......Page 506
12.3 Exploring the business layer and data layers......Page 507
12.4 Developing the application layer......Page 510
12.4.1 Handling constants......Page 512
12.4.2 Organizing utility methods......Page 514
12.4.3 Initializing singletons......Page 516
12.4.4 Adapting business objects......Page 518
12.5 Writing a visit object for session state......Page 525
12.6 Developing a base backing bean class......Page 528
12.7 Summary......Page 532
Building an application: backing beans, security, and internationalization......Page 533
13.1 Writing backing beans......Page 534
13.1.2 Handling errors......Page 535
13.1.3 Performing authentication......Page 539
13.1.4 Listing projects with UIData and parameterizing listeners......Page 545
13.1.5 Updating projects......Page 556
13.1.6 Creating new projects......Page 562
13.1.7 Paging through the project history with UIData......Page 568
13.1.8 Working with JDBC ResultSets and UIData......Page 574
13.2 Adding security......Page 579
13.2.1 Container-based vs. custom security......Page 580
13.2.2 Using custom security......Page 581
13.3 Supporting internationalization in code......Page 585
13.3.1 Internationalizing text with resource bundles......Page 586
13.3.2 Internationalizing messages......Page 591
13.4.1 Accessing the business layer......Page 596
13.4.2 Organizing beans by function......Page 597
13.4.3 Action methods implemented by backing beans......Page 598
13.4.4 Initializing backing bean properties with the Managed Bean Creation facility......Page 599
13.5 Summary......Page 600
Integrating JSF with Struts and existing applications......Page 602
14.2 When to use JSF with other frameworks......Page 603
14.3 The many faces of requests and responses......Page 605
14.4 Integrating JSF with Struts applications......Page 606
14.4.1 First steps......Page 609
14.4.2 Migrating Struts JSP tags......Page 611
14.4.3 Using JSF action methods and managed beans......Page 631
14.4.4 Who’s controlling whom?......Page 633
14.5 Integrating JSF with non-Struts applications......Page 634
14.6 Summary......Page 635
Part 4 - Writing custom components, renderers, validators, and converters......Page 637
The JSF environment: a component developer’s perspective......Page 639
15.1 Three steps to UI extension nirvana......Page 640
15.2 Developing UI components......Page 641
15.2.1 Deciding when to write a UI component......Page 642
15.2.2 Classes and interfaces......Page 644
15.2.3 Event handling with method bindings......Page 657
15.2.4 Registration......Page 658
15.2.5 JSP integration......Page 661
15.3 Developing renderers......Page 670
15.3.1 Deciding when to write a renderer......Page 674
15.3.2 Renderer......Page 675
15.3.3 RenderKit......Page 677
15.3.4 Registration......Page 678
15.3.5 JSP integration......Page 681
15.4 Developing validators......Page 682
15.4.1 Validator......Page 683
15.4.2 Registration......Page 684
15.4.3 JSP integration......Page 686
15.5.1 Converter......Page 688
15.5.2 Registration......Page 691
15.5.3 JSP integration......Page 692
15.7 Packaging UI extensions......Page 694
15.8 Summary......Page 695
Using JSF without JSP......Page 699
A.2 Creating views with class-based pages......Page 700
A.3 Creating views with XUL......Page 704
A.4 Other options......Page 705
references......Page 709
A......Page 713
B......Page 715
C......Page 716
D......Page 717
F......Page 718
H......Page 719
I......Page 721
J......Page 722
L......Page 724
M......Page 725
O......Page 726
P......Page 727
R......Page 728
S......Page 729
U......Page 731
V......Page 734
W......Page 735
X......Page 736
Part 5 - Writing custom components, renderers, validators, and converters: examples......Page 737
UIInputDate: a simple input component......Page 739
16.1 Writing the UIInputDate class......Page 742
16.1.1 Encoding......Page 743
16.1.2 Decoding......Page 749
16.1.3 Implementing StateHolder methods......Page 751
16.3.1 Writing the JSP custom tag......Page 752
16.3.2 Validating the tag......Page 755
16.3.3 Adding the tag to the tag library......Page 756
16.4 Using the component......Page 758
16.5 Summary......Page 759
RolloverButton renderer: a renderer with JavaScript support......Page 761
17.1 Writing the RolloverButtonRenderer class......Page 763
17.1.1 Encoding......Page 765
17.1.2 Decoding......Page 769
17.1.3 Registering the renderer......Page 770
17.2 JSP Integration......Page 771
17.2.1 Writing the HtmlBaseTag class......Page 772
17.2.2 Writing the JSP custom tag......Page 775
17.2.3 Validating the tag......Page 778
17.2.4 Adding the tag to the tag library......Page 779
17.3 Using the renderer......Page 782
17.4.1 Developing the RolloverButtonDecoratorRenderer class......Page 784
17.5 Summary......Page 788
UIHeadlineViewer: a composite, data-aware component......Page 790
18.1 RSS and the Informa API......Page 792
18.2 Using UIData with Informa......Page 797
18.3 Subclassing DataModel......Page 799
18.4 Writing the UIHeadlineViewer class......Page 802
18.5 Registering the component......Page 814
18.6.1 Writing the JSP custom tag......Page 815
18.6.2 Adding the tag to the tag library......Page 821
18.7 Using the component......Page 823
18.8 Summary......Page 827
UINavigator: a model-driven toolbar component......Page 828
19.1 Writing the model classes......Page 830
19.2 Writing the UINavigator class......Page 835
19.2.1 Implementing ActionSource methods......Page 837
19.2.2 Overriding UIComponentBase methods......Page 840
19.2.3 Implementing StateHolder methods......Page 841
19.2.4 Developing NavigatorActionListener: a custom ActionListener......Page 843
19.3 Registering the component......Page 844
19.4.1 Encoding......Page 845
19.4.2 Decoding......Page 854
19.5 Registering the renderer......Page 855
19.6.1 Writing the Navigator_ToolbarTag component tag......Page 856
19.6.2 Writing the NavigatorItemTag tag handler......Page 860
19.6.3 Adding the tags to the tag library......Page 865
19.7 Using the component......Page 868
19.8 Summary......Page 872
Validator and converter examples......Page 873
20.2 Developing a validator......Page 874
20.2.1 Writing the RegularExpressionValidator class......Page 876
20.2.3 Integrating with JSP......Page 881
20.2.4 Using the validator......Page 886
20.4 Developing a converter......Page 888
20.4.1 Writing the UserConverter class......Page 890
20.4.2 Registering the converter......Page 899
20.4.3 JSP integration......Page 900
20.4.4 Using the converter......Page 904
20.5 Summary......Page 906
A survey of JSF IDEs and implementations......Page 907
B.1 Using JSF with Oracle JDeveloper......Page 908
B.1.2 What are ADF Faces Components?......Page 909
B.1.3 Exploring JDeveloper......Page 912
B.1.4 Building ProjectTrack’s Login page......Page 913
B.1.5 Wrapping up......Page 928
B.2 Using JSF with WebSphere Studio......Page 929
B.2.1 Exploring WebSphere Studio......Page 930
B.2.2 Building ProjectTrack’s Login page......Page 932
B.2.3 Wrapping up......Page 950
B.3.1 Using Java Studio Creator......Page 952
B.3.2 Building ProjectTrack’s Login page......Page 954
B.3.3 Wrapping up......Page 966
B.4 JSF implementations......Page 967
Extending the core JSF classes......Page 969
C.1 The classes behind the scenes......Page 970
C.2 Replacing or extending the pluggable classes......Page 974
C.2.1 Configuring a pluggable class......Page 976
C.2.2 Decorating a pluggable class......Page 977
C.2.3 Replacing a pluggable class......Page 981
JSF configuration......Page 992
D.1 Common attributes......Page 994
D.2.2 ......Page 995
D.2.3 ......Page 996
D.3.1 ......Page 997
D.3.2 ......Page 999
D.3.3 ......Page 1002
D.3.4 ......Page 1003
D.4.1 ......Page 1004
D.4.2 ......Page 1005
D.4.4 ......Page 1007
D.5.1 ......Page 1008
D.5.2 ......Page 1009
Time zone, country, language, and currency codes......Page 1010
E.1 Time zone codes......Page 1011
E.2 Language codes......Page 1024
E.3 Country codes......Page 1028
E.4 Currency codes......Page 1036
references......Page 1045
A......Page 1049
B......Page 1051
C......Page 1052
D......Page 1053
F......Page 1054
H......Page 1055
I......Page 1057
J......Page 1058
L......Page 1060
M......Page 1061
O......Page 1062
P......Page 1063
R......Page 1064
S......Page 1065
U......Page 1067
V......Page 1070
W......Page 1071
X......Page 1072