Read an Excerpt
When we heard about JavaServer Faces (JSF) at the 2002 JavaOne 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 Core Java™, 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 Faces 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 was a member) until 2004 to release the JSF 1.0 specification and reference implementation. A bug fix 1.1 release emerged shortly afterwards, and an incremental 1.2 release added a number of cleanups and convenience features in 2006.
JSF is now the preeminent server-side Java web framework, and it has fulfilled most of its promises. You really can design web user interfaces by putting components on a form and linking them to Java objects, without having to mix code and markup. A strong point of JSF is its extensible component model, and a large number of third-party components have become available. The flexible design of the framework has allowed it to grow well and accommodate new technologies such as Ajax. The framework was designed for tool support, and usable drag-and-drop GUI builders have finallyemerged. And finally, unlike competing technologies 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, navigation, connections with external services, and configuration management.
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
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 framework implementors, as well as long-suffering book authors.
The first half of the book, extending through Chapter 6, focuses on the JSF tags. 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 the tags. We 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 Chapter 7, we begin JSF programming in earnest. You will learn how to perform advanced tasks, and how to extend the JSF framework. Here are the main topics of the second part:
- Event handling (Chapter 7)
- Including common content among multiple pages (Chapter 8)
- Implementing custom components, converters, and validators
- (Chapter 9)
- Connecting to databases and other external services (Chapter 10)
- Ajax (Chapter 11)
- Open source technologies, with a focus on Facelets, Seam, and Shale (Chapter 12)
We end the book with a chapter that aims to answer common questions of the form “How do I . . . ” (see Chapter 13). 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, such as file uploads, pop-up 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 and an application server that supports JSF, such as the excellent open source GlassFish project. The software runs identically on Linux, Mac OS X, Solaris, and Windows. We used Java 5 and GlassFish on both Linux and Mac OS X to develop the code examples in the book.
If you are looking for a development environment that supports JSF development, we can heartily recommend the freely available NetBeans IDE. Good JSF support for Eclipse is available from several vendors that sell Eclipse enhancements. 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