1. Trang chủ
  2. » Khoa Học Tự Nhiên

PTRC java server

1,6K 88 0

Đang tải... (xem toàn văn)

Tài liệu hạn chế xem trước, để xem đầy đủ mời bạn chọn Tải xuống

THÔNG TIN TÀI LIỆU

Thông tin cơ bản

Định dạng
Số trang 1.618
Dung lượng 7,29 MB

Nội dung

This document is created with a trial version of CHM2PDF Pilot http://www.colorpilot.com < Day Day Up > • • 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 < Day Day Up > This document is created with a trial version of CHM2PDF Pilot http://www.colorpilot.com < Day Day Up > • • 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 Getting Started Why JavaServer Faces Software Installation A Simple Example Sample Application Analysis Visual Development Environments JSF Framework Services Behind the Scenes Automation of the Build Process with Ant Chapter Managed Beans Definition of a Bean Message Bundles A Sample Application Backing Beans Bean Scopes Configuring Beans The Syntax of Value Binding Expressions Chapter Navigation Static Navigation Dynamic Navigation Advanced Navigation Issues Chapter Standard JSF Tags An Overview of the JSF Core Tags An Overview of the JSF HTML Tags Forms This document is created with a trial version of CHM2PDF Pilot http://www.colorpilot.com Forms Text Fields and Text Areas Buttons and Links Selection Tags Messages Panels Chapter Data Tables The Data Table Tag A Simple Table h:dataTable Attributes Headers and Footers JSF Components in Table Cells Editing Table Cells Styles for Rows and Columns Database Tables Table Models Scrolling Techniques Chapter Conversion and Validation Overview of the Conversion and Validation Process Using Standard Converters Using Standard Validators Programming with Custom Converters and Validators Implementing Custom Tags Chapter Event Handling Life-Cycle Events Value Change Events Action Events Event Listener Tags Immediate Components Phase Events Putting It All Together Chapter Subviews and Tiles Common Layouts A Book Viewer and a Library The Book Viewer Content Inclusion in the Book Viewer The Library Chapter Custom Components Implementing Custom Components with Classes Encoding: Generating Markup Decoding: Processing Request Values Implementing Custom Component Tags Revisiting the Spinner 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 This document is created with a trial version of CHM2PDF Pilot http://www.colorpilot.com Mobile Communication and Control Flow Component Implementation for Mobile Clients The Battleship Game Chapter 12 How Do I… Web User Interface Design Validation Programming Debugging and Logging Index < Day Day Up > This document is created with a trial version of CHM2PDF Pilot http://www.colorpilot.com < Day Day Up > 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 TRADEMARKS—HotJava, 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 < Day Day Up > This document is created with a trial version of CHM2PDF Pilot http://www.colorpilot.com < Day Day Up > 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 < Day Day Up > This document is created with a trial version of CHM2PDF Pilot http://www.colorpilot.com < Day Day Up > 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 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 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 extensible—you 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 stuff— separation 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 with utility classes in the com.corejsf.util 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 < Day Day Up > This document is created with a trial version of CHM2PDF Pilot http://www.colorpilot.com < Day Day Up > 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 to the middle of 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 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 and 5) Converting and validating input (Chapter 6) Starting with the final sections of Chapter 6, 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: 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) Supporting wireless clients (Chapter 11) We end the book with a chapter that aims to answer common questions of the form "How 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 not assume any such knowledge < Day Day Up > This document is created with a trial version of CHM2PDF Pilot http://www.colorpilot.com < Day Day Up > 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 implementation The software runs identically on Linux, Mac OS X, Solaris, and Windows 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 available in the near future < Day Day Up > This document is created with a trial version of CHM2PDF Pilot http://www.colorpilot.com < Day Day Up > 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 < Day Day Up > This document is created with a trial version of CHM2PDF Pilot http://www.colorpilot.com 99394 EC Example Caption Example 0-1 : index.jsp 99548 EC Example Number Listing 11-10 < Day Day Up > This document is created with a trial version of CHM2PDF Pilot http://www.colorpilot.com < Day Day Up > [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 This document is created with a trial version of CHM2PDF Pilot http://www.colorpilot.com 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 < Day Day Up > This document is created with a trial version of CHM2PDF Pilot http://www.colorpilot.com < Day Day Up > [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 < Day Day Up > This document is created with a trial version of CHM2PDF Pilot http://www.colorpilot.com < Day Day Up > [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 This document is created with a trial version of CHM2PDF Pilot http://www.colorpilot.com View [See MVC] view IDs navigation view tag visual development environments < Day Day Up > This document is created with a trial version of CHM2PDF Pilot http://www.colorpilot.com < Day Day Up > [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 < Day Day Up > This document is created with a trial version of CHM2PDF Pilot http://www.colorpilot.com < Day Day Up > [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 < Day Day Up > This document is created with a trial version of CHM2PDF Pilot http://www.colorpilot.com < Day Day Up > • • 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 < Day Day Up > This document is created with a trial version of CHM2PDF Pilot http://www.colorpilot.com < Day Day Up > 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 < Day Day Up > This document is created with a trial version of CHM2PDF Pilot http://www.colorpilot.com < Day Day Up > 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 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 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 extensible—you 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 stuff— separation 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 with utility classes in the com.corejsf.util 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 < Day Day Up > This document is created with a trial version of CHM2PDF Pilot http://www.colorpilot.com < Day Day Up > Acknowledgments 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, PushToTest Rob Gordon, Crooked Furrow Farm Marty Hall, author of Core Java Servlets and JavaServer Pages Jeff Markham, Markham Software Company Angus McIntyre, IBM Corporation John Muchow, author of Core J2ME Sergei Smirnov, principal architect of Exadel JSF Studio Roman Smolgovsky, Flytecomm Stephen Stelting, Sun Microsystems, Inc Christopher Taylor, Nanshu Densetsu 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 < Day Day Up > This document is created with a trial version of CHM2PDF Pilot http://www.colorpilot.com < Day Day Up > • • 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 Getting Started Why JavaServer Faces Software Installation A Simple Example Sample Application Analysis Visual Development Environments JSF Framework Services Behind the Scenes Automation of the Build Process with Ant Chapter Managed Beans Definition of a Bean Message Bundles A Sample Application Backing Beans Bean Scopes Configuring Beans The Syntax of Value Binding Expressions Chapter Navigation Static Navigation Dynamic Navigation Advanced Navigation Issues Chapter Standard JSF Tags An Overview of the JSF Core Tags An Overview of the JSF HTML Tags Forms This document is created with a trial version of CHM2PDF Pilot http://www.colorpilot.com Forms Text Fields and Text Areas Buttons and Links Selection Tags Messages Panels Chapter Data Tables The Data Table Tag A Simple Table h:dataTable Attributes Headers and Footers JSF Components in Table Cells Editing Table Cells Styles for Rows and Columns Database Tables Table Models Scrolling Techniques Chapter Conversion and Validation Overview of the Conversion and Validation Process Using Standard Converters Using Standard Validators Programming with Custom Converters and Validators Implementing Custom Tags Chapter Event Handling Life-Cycle Events Value Change Events Action Events Event Listener Tags Immediate Components Phase Events Putting It All Together Chapter Subviews and Tiles Common Layouts A Book Viewer and a Library The Book Viewer Content Inclusion in the Book Viewer The Library Chapter Custom Components Implementing Custom Components with Classes Encoding: Generating Markup Decoding: Processing Request Values Implementing Custom Component Tags Revisiting the Spinner 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 This document is created with a trial version of CHM2PDF Pilot http://www.colorpilot.com Mobile Communication and Control Flow Component Implementation for Mobile Clients The Battleship Game Chapter 12 How Do I… Web User Interface Design Validation Programming Debugging and Logging Index < Day Day Up > ... patents, foreign patents, or pending applications TRADEMARKS—HotJava, Java, Java Development Kit, J2EE, JPS, JavaServer Pages, Enterprise JavaBeans, EJB, JDBC, J2SE, Solaris, SPARC, SunOS, and Sunsoft... promise of JavaServer Faces is to bring rapid user-interface development to server- side Java If you are familiar with client-side Java development, you can think of JSF as "Swing for server- side... The Java SDK 1.4.1 or higher (http:/ /java. sun.com/j2se) The Tomcat servlet container (http://jakarta.apache.org/tomcat/) The JavaServer Faces reference implementation (http:/ /java. sun.com/j2ee/javaserverfaces)

Ngày đăng: 25/03/2019, 15:02

w