Core JavaServer Faces (Sun Microsystems Press Java Series) - ISBN 0131463055.pdf

(22256 KB) Pobierz
146572188 UNPDF
Faces (JSF) at the 2002 Java One conference,
we were very excited. Both of us had extensive experience with client-side Java
programming, and had lived to tell the tale—David in
Graphic Java
, and Cay in
, both published by Sun Microsystems Press. When we first tried web
programming with servlets and JavaServer Pages (JSP), we found it to be
rather unintuitive and tedious. JavaServer
promised to put a friendly face
in front of a web application, allowing programmers to think about text fields
and menus instead of fretting over page flips and request parameters. Each of
us proposed a book project to the publisher, who promptly suggested that we
should jointly write the Sun Microsystems Press book on this technology.
It took the JSF expert group (of which David is a member) another two years to
release the JSF 1.0 specification and reference implementation. This release ful-
fills many of the original promises. You really can design web user interfaces
by putting components on a form and linking them to Java objects, without
having to write any code at all. The framework was designed for tool support,
and the first batch of drag-and-drop GUI builders is now emerging. The frame-
work is extensible—you are not limited to the standard set of HTML compo-
nents, and you can even use completely different rendering technologies, to
support, for example, wireless devices. And finally, unlike competing technolo-
gies that let you tumble down a deep cliff once you step beyond the glitz, JSF
supports the hard stuff—separation of presentation and business logic, naviga-
tion, connections with external services, and configuration management.
Faces
When we heard about JavaServer
Core Java
146572188.163.png 146572188.174.png 146572188.185.png 146572188.196.png 146572188.001.png 146572188.012.png 146572188.023.png 146572188.034.png 146572188.045.png 146572188.056.png 146572188.067.png 146572188.078.png 146572188.089.png 146572188.100.png 146572188.111.png 146572188.122.png 146572188.125.png 146572188.126.png 146572188.127.png 146572188.128.png 146572188.129.png 146572188.130.png 146572188.131.png 146572188.132.png 146572188.133.png 146572188.134.png 146572188.135.png 146572188.136.png 146572188.137.png 146572188.138.png 146572188.139.png 146572188.140.png 146572188.141.png 146572188.142.png 146572188.143.png 146572188.144.png 146572188.145.png 146572188.146.png 146572188.147.png 146572188.148.png 146572188.149.png 146572188.150.png
xvi
Preface
Of course, being a 1.0 release, the current version of JSF is far from perfect.
Some of the APIs are awkward. We supply you with utility classes in the
package to reduce your pain. Also, there are fewer components
than we originally expected. While JSF has a powerful and convenient data
table component, some useful components such as tabbed panes, scrollers, file
uploads, and so on, were not included for lack of time. In the book, we show
you how to implement these features. Of course, we expect the next release of
JSF to remedy many of these shortcomings.
We are still excited about JSF, and we hope you will share this excitement when
you learn how this technology makes you a more effective web application
developer.
About This Book
. These tags are similar to HTML form tags. They are the basic building
blocks for JSF user interfaces. No programming is required for use of to use the
tags. We only assume only basic HTML skills for web pages and standard Java
programming for the business logic.
The first part of the book covers these topics:
• Setting up your programming environment (Chapter 1)
• Connecting JSF tags to application logic (Chapter 2)
• Navigating between pages (Chapter 3)
• Using the standard JSF tags (Chapters 4 and 5)
• Converting and validating input (Chapter 6)
Starting with the final sections of Chapter 6, we begin JSF programming in ear-
nest. You will learn how to perform advanced tasks, and how to extend the JSF
framework. Here are the main topics of the second part:
tags
Implementing custom converters and validators (Chapter 6)
Event handling (Chapter 7)
Including common content among multiple pages (Chapter 8)
Implementing custom components (Chapter 9)
Connecting to databases and other external services (Chapter 10)
com.corejsf.util
This book is suitable for web developers whose main focus is user interface
design, as well as for programmers who implement reusable components for
web applications. This is in stark contrast to the official JSF specification, a
dense and pompously worded document whose principal audience is frame-
work implementors, as well as long-suffering book authors.
The first half of the book, extending to the middle of Chapter 6, focuses on the
JSF
146572188.151.png 146572188.152.png 146572188.153.png 146572188.154.png 146572188.155.png 146572188.156.png 146572188.157.png 146572188.158.png 146572188.159.png 146572188.160.png 146572188.161.png 146572188.162.png 146572188.164.png 146572188.165.png 146572188.166.png 146572188.167.png 146572188.168.png 146572188.169.png 146572188.170.png 146572188.171.png 146572188.172.png 146572188.173.png 146572188.175.png 146572188.176.png 146572188.177.png 146572188.178.png 146572188.179.png 146572188.180.png 146572188.181.png 146572188.182.png 146572188.183.png 146572188.184.png 146572188.186.png 146572188.187.png 146572188.188.png 146572188.189.png 146572188.190.png 146572188.191.png 146572188.192.png 146572188.193.png 146572188.194.png
Preface
xvii
• Supporting wireless clients (Chapter 11)
We end the book with a chapter that aims to answer common questions of the
form “How do I….?” We encourage you to have a peek at that chapter as soon
as you become comfortable with the basics of JSF. There are helpful notes on
debugging and logging, and we also give you implementation details and
working code for features that are missing from JSF 1.0, such as file uploads,
popup menus, and a pager component for long tables.
JSF is built on top of servlets and JSP, but from the point of view of the JSF
developer, these technologies merely form the low-level plumbing. While it
can’t hurt to be familiar with other web technologies such as servlets, JSP, or
Struts, we do not assume any such knowledge.
Required Software
All software that you need for this book is freely available. You need the Java
Software Development Kit from Sun Microsystems, a servlet container such as
Tomcat, and, of course, a JSF implementation, such as Sun’s reference imple-
mentation. The software runs identically on Linux, Mac OS X, Solaris, and Win-
dows. We used the 1.4.2 J2SE and Tomcat 5.0.19 on both Linux and Mac OS X to
develop the code examples in the book.
We also expect that integrated environments will become commercially avail-
able in the near future.
Web Support
The web page for this book is
http://corejsf.com
. It contains
The source code for all examples in this book
Useful reference material that we felt is more effective in browseable form
than in print
A list of known errors in the book and the code
A form for submitting corrections and suggestions
146572188.195.png 146572188.197.png 146572188.198.png 146572188.199.png 146572188.200.png 146572188.201.png 146572188.202.png 146572188.203.png 146572188.204.png 146572188.205.png 146572188.206.png 146572188.002.png 146572188.003.png 146572188.004.png 146572188.005.png 146572188.006.png 146572188.007.png 146572188.008.png 146572188.009.png 146572188.010.png 146572188.011.png 146572188.013.png 146572188.014.png 146572188.015.png 146572188.016.png 146572188.017.png 146572188.018.png 146572188.019.png 146572188.020.png 146572188.021.png 146572188.022.png 146572188.024.png 146572188.025.png 146572188.026.png 146572188.027.png 146572188.028.png 146572188.029.png 146572188.030.png 146572188.031.png 146572188.032.png 146572188.033.png
146572188.035.png 146572188.036.png 146572188.037.png 146572188.038.png 146572188.039.png 146572188.040.png 146572188.041.png 146572188.042.png 146572188.043.png 146572188.044.png 146572188.046.png 146572188.047.png 146572188.048.png 146572188.049.png 146572188.050.png 146572188.051.png 146572188.052.png 146572188.053.png 146572188.054.png 146572188.055.png 146572188.057.png 146572188.058.png 146572188.059.png 146572188.060.png 146572188.061.png 146572188.062.png 146572188.063.png 146572188.064.png 146572188.065.png 146572188.066.png 146572188.068.png 146572188.069.png 146572188.070.png 146572188.071.png 146572188.072.png 146572188.073.png 146572188.074.png 146572188.075.png 146572188.076.png 146572188.077.png 146572188.079.png
First and foremost, we’d like to thank Greg Doench, our editor at Prentice Hall,
who has shepherded us through this project, never losing his nerve in spite of
numerous delays and complications. Thanks to Mary Lou Nohr for editing the
manuscript, and to Patti Guerrieri for her production work. We very much
appreciate our reviewers who have done a splendid job, finding errors and
suggesting improvements in various drafts of the manuscript. They are:
Larry Brown
Frank Cohen
Rob Gordon, all-around Java guru and author of
Essential JNI
Marty Hall, author of
Core Java Servlets and JavaServer Pages
Jeff Markham
Angus McIntyre
John Muchow, author of
Core J2ME
Sergei Smirnov of Exadel Inc.
Roman Smolgovsky of Flytecomm
Stephen Stelting
Christopher Taylor
Michael Yuan, author of
Enterprise J2ME
Finally, thanks to our families and friends who have supported us through this
project and who share our relief that it is finally completed.
146572188.080.png 146572188.081.png 146572188.082.png 146572188.083.png 146572188.084.png 146572188.085.png 146572188.086.png 146572188.087.png 146572188.088.png 146572188.090.png 146572188.091.png 146572188.092.png 146572188.093.png 146572188.094.png 146572188.095.png 146572188.096.png 146572188.097.png 146572188.098.png 146572188.099.png 146572188.101.png 146572188.102.png 146572188.103.png 146572188.104.png 146572188.105.png 146572188.106.png 146572188.107.png 146572188.108.png 146572188.109.png 146572188.110.png 146572188.112.png 146572188.113.png 146572188.114.png 146572188.115.png 146572188.116.png 146572188.117.png 146572188.118.png 146572188.119.png 146572188.120.png 146572188.121.png 146572188.123.png 146572188.124.png
Zgłoś jeśli naruszono regulamin