• • Table of Contents Index core JavaServer™ Faces By DAVID GEARY, CAY HORSTMANN Publisher : Addison Wesley Pub Date : June 15, 2004 ISBN : 0-13-146305-5 Pages : 552 JavaServer Faces promises to bring rapid user-interface development to server-side Java It allows developers to painlessly write server-side applications without worrying about the complexities of dealing with browsers and Web servers It also automates low-level, boring details like control flow and moving code between web forms and business logic JavaServer Faces was designed to support drag and drop development of server-side applications, but you can also think of it as a conceptual layer on top of servlets and JavaServer Pages (JSP) Experienced JSP developers will find that JavaServer Faces provides much of the plumbing that they currently have to implement by hand If you already use a server-side framework such as Struts, you will find that JavaServers Faces uses a similar architecture, but is more flexible and extensible JavaServer Faces also comes with server-side components and an event model, which are fundamentally similar to the same concepts in Swing JavaServer Faces is quickly becoming the standard Web-application framework Core JavaServer Faces is the one book you need to master this powerful and time-saving technology Without assuming knowledge of JSP and servlets, Core JavaServer Faces: shows how to build more robust applications and avoid tedious handcoding answers questions most developers don't even know to ask demonstrates how to use JSF with Tiles to build consistent user interfaces automatically provides hints, tips, and explicit "how-to" information that allows you to quickly become more productive explains how to integrate JSF with databases, use directory services, wireless apps, and Web services teaches best practices and good habits like using style sheets and message bundles covers all of the JSF tags and how to create new tag libraries • • Table of Contents Index core JavaServer™ Faces By DAVID GEARY, CAY HORSTMANN Publisher : Addison Wesley Pub Date : June 15, 2004 ISBN : 0-13-146305-5 Pages : 552 Copyright About Prentice Hall Professional Technical Reference Preface About This Book Required Software Web Support Acknowledgments Chapter 1 Getting Started Why JavaServer Faces Software Installation Sample Application Analysis JSF Framework Services A Simple Example Visual Development Environments Behind the Scenes Automation of the Build Process with Ant Chapter 2 Managed Beans Definition of a Bean Message Bundles A Sample Application Backing Beans Configuring Beans Bean Scopes The Syntax of Value Binding Expressions Chapter 3 Navigation Static Navigation Dynamic Navigation Advanced Navigation Issues Chapter 4 Standard JSF Tags An Overview of the JSF Core Tags An Overview of the JSF HTML Tags Text Fields and Text Areas Selection Tags Forms Buttons and Links Messages Panels Chapter 5 Data Tables The Data Table Tag A Simple Table Headers and Footers Editing Table Cells Database Tables h:dataTable Attributes JSF Components in Table Cells Styles for Rows and Columns Table Models Scrolling Techniques Chapter 6 Conversion and Validation Overview of the Conversion and Validation Process Using Standard Converters Programming with Custom Converters and Validators Using Standard Validators Implementing Custom Tags Chapter 7 Event Handling Life-Cycle Events Value Change Events Action Events Event Listener Tags Immediate Components Phase Events Putting It All Together Chapter 8 Subviews and Tiles Common Layouts A Book Viewer and a Library Content Inclusion in the Book Viewer The Book Viewer The Library Chapter 9 Custom Components Implementing Custom Components with Classes Encoding: Generating Markup Decoding: Processing Request Values Revisiting the Spinner Implementing Custom Component Tags Encoding JavaScript to Avoid Server Roundtrips Using Child Components and Facets Chapter 10 External Services Accessing a Database Using LDAP for Authentication Managing Configuration Information Using Web Services Chapter 11 Wireless Clients Rendering Technologies for Mobile Clients MIDP Basics Component Implementation for Mobile Clients Mobile Communication and Control Flow The Battleship Game Chapter 12 How Do I… Web User Interface Design Validation Programming Debugging and Logging Index Copyright © 2004 Sun Microsystems, Inc Printed in the United States of America 4150 Network Circle, Santa Clara, California 95054 U.S.A All rights reserved This product and related documentation are protected by copyright and distributed under licenses restricting its use, copying, distribution, and decompilation No part of this product or related documentation may be reproduced in any form by any means without prior written authorization of Sun and its licensors, if any RESTRICTED RIGHTS LEGEND: Use, duplication, or disclosure by the United States Government is subject to the restrictions set forth in DFARS 252.227-7013 (c)(1)(ii) and FAR 52.227-19 The products described may be protected by one or more U.S patents, foreign patents, or pending applications TRADEMARKSHotJava, Java, Java Development Kit, J2EE, JPS, JavaServer Pages, Enterprise JavaBeans, EJB, JDBC, J2SE, Solaris, SPARC, SunOS, and Sunsoft are trademarks of Sun Microsystems, Inc All other products or services mentioned in this book are the trademarks or service marks of their respective companies or organizations Prentice Hall PTR offers excellent discounts on this book when ordered in quantity for bulk purchases or special sales For more information, please contact U.S Corporate and Government Sales, 1-800-382-3419, corpsales@pearsontechgroup.com For sales outside of the U.S., please contact International Sales, 1-317-5813793, international@pearsontechgroup.com Acquisitions Editor: Gregory G Doench Editorial Assistant: Raquel Kaplan Production Supervision: Patti Guerrieri Cover Design Director: Jerry Votta Cover Designer: Anthony Gemmellaro Art Director: Gail Cocker-Bogusz Manufacturing Manager: Alexis R Heydt Marketing Manager: Chris Guzikowski Sun Microsystems Press Publisher: Myrna Rivera First Printing Sun Microsystems Press A Prentice Hall Title About Prentice Hall Professional Technical Reference With origins reaching back to the industry's first computer science publishing program in the 1960s, and formally launched as its own imprint in 1986, Prentice Hall Professional Technical Reference (PH PTR) has developed into the leading provider of technical books in the world today Our editors now publish over 200 books annually, authored by leaders in the fields of computing, engineering, and business Our roots are firmly planted in the soil that gave rise to the technical revolution Our bookshelf contains many of the industry's computing and engineering classics: Kernighan and Ritchie's C Programming Language, Nemeth's UNIX System Administration Handbook, Horstmann's Core Java, and Johnson's High-Speed Digital Design PH PTR acknowledges its auspicious beginnings while it looks to the future for inspiration We continue to evolve and break new ground in publishing by providing today's professionals with tomorrow's solutions Preface When we heard about JavaServer™ 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 taleDavid 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 is a member) another two years to release the JSF 1.0 specification and reference implementation This release fulfills 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 framework is extensibleyou are not limited to the standard set of HTML components, and you can even use completely different rendering technologies, to support, for example, wireless devices And finally, unlike competing technologies that let you tumble down a deep cliff once you step beyond the glitz, JSF supports the hard stuffseparation of presentation and business logic, navigation, connections with external services, and configuration management 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 container-managed and logging container-managed, example handling consistently select HTML tags select tags selection tags selectItems tag what to specify separation of concerns server, roundtrip to services, external, using with JSF servlets configuration for simple login example exception attributes servlet container services servlet mapping servlet request dispatcher in tabbed pane renderer Tomcat overview sessions objects, keeping alive during session scope 2nd 3rd session scope lifespan tracking setup and installation shape attribute shortcuts application, remember whether deployed build process CSS and HTML tags pi mnemonic selectItems attribute mnemonic size attribute SOAP defined libraries required for sorting columns dataTable example models, overriding setRowIndex SortFilterModel class sorting model spinner converter custom component example custom components drawbacks JavaScript SQL basics information sources stack trace, deciphering standard error message text standard JSF tags [See also JSF, tags] overview standard validation error messages standard validators state saving with cookies saving with URL rewriting state, saving and restoring 2nd statements, prepared static navigation navigation rules overview strings [See also message bundles] collecting conversion in beans validation Struts tiles, installing validation, client-side style attribute styleClass attribute styles HTML tags subviews examples subview tag using Sun Java System Directory Server syntax, JSF versus HTML [SYMBOL] [A] [B] [C] [D] [E] [F] [G] [H] [I] [J] [K] [L] [M] [N] [O] [P] [Q] [R] [S] [T] [U] [V] [W] [X] tabbed panes child components content inclusion custom component example 2nd custom components example facets key features reference implementation renderer specifying content state, saving and restoring using tabindex attribute tables [See also rows, columns] CSS classes for dataTable data tables database tables editing cell contents filtering headers and footers JSF components in models models, editing scrolling simple example simple example, code sorting sorting table columns styles tag handler class, how used tags [See also core library, HTML library] buttons client-side validation core library custom tag validation event listener how they work HTML tags image display item selection tags JSF tags, types of links messages packaging in JAR file prefix conventions selection tags standard JSF 2nd tag class responsibilities tag handler, custom components text display text input attributes text input complete example text input examples writing client-side validation target attribute text displaying, tags error messages text areas attribute examples attributes complete example text fields attribute examples attributes complete example threads in MIDP tiles book viewer, using in 2nd controllers extending installing nested parameterizing using title attribute Tomcat auto deploy database pool parameters database resource, configuration logs, finding overview realm configuration servlet container requirements starting tool support for framework services trace, deciphering stack trace translations message bundle encoding quiz application type attribute 2nd [SYMBOL] [A] [B] [C] [D] [E] [F] [G] [H] [I] [J] [K] [L] [M] [N] [O] [P] [Q] [R] [S] [T] [U] [V] [W] [X] undeploying and Ant Unicode characters beyond 127 encoding UNIX installation and setup Update Model phase uploads, supporting URLs for JSF user interface [See also presentation] Battleship on mobile client error pages, customizing examples file uploads image maps large data set, displaying popup windows UserBean code and explanation code in login application customizing instance of package properties users [See also authorization] LDAP example user data, bean-managed UTF and encoding [SYMBOL] [A] [B] [C] [D] [E] [F] [G] [H] [I] [J] [K] [L] [M] [N] [O] [P] [Q] [R] [S] [T] [U] [V] [W] [X] validateDoubleRange tag validateLength tag validateLongRange tag validation bean methods bypassing classes client-side with Jakarta Commons Validator client-side, writing tag components, relationships among CreditCard class custom tags custom validation custom validators, registering errors, displaying example examples HTML tags Luhn formula numeric range overview relationships among multiple components required values string length Struts and client-side validation using validators, standard validation and error handling validator attribute Struts client-side validation tag value attribute 2nd value binding bean scopes bean value-binding expressions composite expressions custom components expressions resolvers for extending JSF expressions syntax use of single quotes in expressions value of converter attribute value change events 2nd 3rd valueChangeListener attribute 2nd tag values HTML tags local values, why use submitting using hidden fields value-binding expressions variable resolver verbatim tag View [See MVC] view IDs navigation view tag visual development environments [SYMBOL] [A] [B] [C] [D] [E] [F] [G] [H] [I] [J] [K] [L] [M] [N] [O] [P] [Q] [R] [S] [T] [U] [V] [W] [X] WAP compared to WML defined WAR files [See also directory structure] defined manual deployment phase tracker shortcuts web container and configuration files web services Amazon Web Services example code Java Web Services Developer Pack libraries primary benefit search example using welcome file for simple login example widgets, page width attribute wildcards for navigation Windows installation and setup windows, popup wireless clients [See also mobile clients, cell phones, J2ME, MIDP] testing writing applications for wireless toolkit from Sun WML compared to WAP defined WSDL Amazon Web Services example defined what it specifies [SYMBOL] [A] [B] [C] [D] [E] [F] [G] [H] [I] [J] [K] [L] [M] [N] [O] [P] [Q] [R] [S] [T] [U] [V] [W] [X] XHTML cell phones and defined XUL defined demo more information Mozilla browser ... Table of Contents Index core JavaServer Faces By DAVID GEARY, CAY HORSTMANN Publisher : Addison Wesley Pub Date : June 15, 2004 ISBN : 0-13-146305-5 Pages : 552 Copyright About Prentice Hall Professional Technical Reference... event model, which are fundamentally similar to the same concepts in Swing JavaServer Faces is quickly becoming the standard Web-application framework Core JavaServer Faces is the one book you need to master this powerful and time-saving... (http://jakarta.apache.org/tomcat/) The JavaServer Faces reference implementation (http://java.sun.com/j2ee/javaserverfaces) The sample code for this book, available at http://corejsf.com We assume that you already installed the Java SDK and that