冀ajax214,Pro JSF and Ajax1.pdf

44cb7578e1df5412b94317daaa3307ba.gifPro JSF and Ajax1.pdf

Jonas Jacobi and John R Fallows Pro JSF and Ajax Building Rich Internet Components 5807fm qxd 1 20 06 4 11 PM Page i Pro JSF and Ajax Building Rich Internet Components Copyright 2006 by Jonas Jacobi and John R Fallows All rights reserved No part of this work may be reproduced or transmitted in any form or by any means electronic or mechanical including photocopying recording or by any information storage or retrieval system without the prior written permission of the copyright owner and the publisher ISBN 13 978 1 59059 580 0 ISBN 10 1 59059 580 7 Printed and bound in the United States of America 9 8 7 6 5 4 3 2 1 Trademarked names may appear in this book Rather than use a trademark symbol with every occurrence of a trademarked name we use the names only in an editorial fashion and to the benefit of the trademark owner with no intention of infringement of the trademark Lead Editor Tony Davis Technical Reviewers Peter Lubbers Kito D Mann Matthias Wessendorf Editorial Board Steve Anglin Dan Appleman Ewan Buckingham Gary Cornell Jason Gilmore Jonathan Hassell James Huddleston Chris Mills Matthew Moodie Dominic Shakeshaft Jim Sumser Matt Wade Project Managers Beckie Stones Elizabeth Seymour Copy Edit Manager Nicole LeClerc Copy Editor Kim Wimpsett Assistant Production Director Kari Brooks Copony Production Editor Laura Cheu Compositor Molly Sharp ContentWorks Proofreader Elizabeth Berry Indexer Carol Burbo Artist Kinetic Publishing Services LLC Cover Designer Kurt Krames Manufacturing Director Tom Debolski Distributed to the book trade worldwide by Springer Verlag New York Inc 233 Spring Street 6th Floor New York NY 10013 Phone 1 800 SPRINGER fax 201 348 4505 e mail orders ny springer or visit For information on translations please contact Apress directly at 2560 Ninth Street Suite 219 Berkeley CA 94710 Phone 510 549 5930 fax 510 549 5939 e mail info or visit The information in this book is distributed on an as is basis without warranty Although every precaution has been taken in the preparation of this work neither the author s nor Apress shall have any liability to any person or entity with respect to any loss or damage caused or alleged to be caused directly or indirectly by the information contained in this work 5807fm qxd 1 20 06 4 11 PM Page ii To the love of my life Marianne and our princesses Emma and Isabelle for keeping my spirit up Jonas Jacobi To my wife Nan for her love support and patience and our son Jack for his natural inspiration John R Fallows 5807fm qxd 1 20 06 4 11 PM Page iii 5807fm qxd 1 20 06 4 11 PM Page iv Contents at a Glance Foreword xiii About the Authors xv About the Technical Reviewers xvii Acknowledgments xix Introduction xxi PART 1 I I IDeveloping Smarter with JavaServerTMFaces ICHAPTER 1The Foundation of JSF Components 3 ICHAPTER 2Defining the Date Field Component 49 ICHAPTER 3Defining the Deck Component 105 PART 2 I I IDesigning Rich Internet Components ICHAPTER 4Using Rich Internet Technologies 173 ICHAPTER 5Loading Resources with Weblets 213 ICHAPTER 6Ajax Enabling the Deck Component 223 ICHAPTER 7Ajax Enabling the Date Field Component 267 ICHAPTER 8Providing Mozilla XUL Renderers 303 ICHAPTER 9Providing Microsoft HTC Renderers 361 ICHAPTER 10Switching RenderKits Dynamically 403 IINDEX 413 v 5807fm qxd 1 20 06 4 11 PM Page v 5807fm qxd 1 20 06 4 11 PM Page vi Contents Foreword xiii About the Author xv About the Technical Reviewer xvii Acknowledgments xix Introduction xxi PART 1 I I IDeveloping Smarter with JavaServerTMFaces ICHAPTER 1The Foundation of JSF Components 3 Overview of Application Development Technologies 4 One Tier 4 Two Tier Client Server 5 Multitier Web Applications 5 Exploring Application Development Today 5 Frameworks 7 Tapestry Struts Tiles TopLink Hibernate ADF UIX 7 Introducing JSF 8 Application Development with JSF 9 JSF Architecture 10 A Component Based UI Framework 13 UIComponent 15 Converters Validators Events and Listeners 22 Facets 23 Renderers 24 Renderer Types 25 RenderKits 26 Custom Action Tag Handlers 27 Request Processing Lifecycle 27 Summary 47 vii 5807fm qxd 1 20 06 4 11 PM Page vii ICHAPTER 2Defining the Date Field Component 49 Requirements for the Date Field Component 49 The Input Date Component 51 Designing the Input Date Component Using a Blueprint 52 Step 1 Creating a UI Prototype 53 Step 2 Creating a Client Specific Renderer 55 Step 3 Creating a Renderer Specific Subclass 77 Step 4 Registering UIComponent and Renderer 82 Step 5 Creating a JSP Tag Handler and TLD 86 Building an Application with the Input Date Component 103 Summary 104 ICHAPTER 3Defining the Deck Component 105 Requirements for the Deck Component 106 The Deck Component 106 Designing the Deck Component Using a Blueprint 107 Step 1 Creating a UI Prototype 108 Step 2 Creating Events and Listeners 113 Step 3 Creating a Behavioral Superclass 127 Step 4 Creating a Client Specific Renderer 136 Step 5 Creating a Renderer Specific Subclass 148 Step 6 Registering a UIComponent and Renderer 150 Step 7 Creating a JSP Tag Handler and TLD 155 Summary 169 PART 2 I I IDesigning Rich Internet Components ICHAPTER 4Using Rich Internet Technologies 173 Introducing Ajax 174 The XMLHttpRequest Object 175 Traditional Web Application Development 177 Ajax Web Application Development 179 Building Ajax Applications 181 Ajax Summary 187 Introducing Mozilla XUL 187 Building XUL Applications 188 Creating Custom XUL Components Using XBL 192 XUL Summary 199 ICONTENTSviii 5807fm qxd 1 20 06 4 11 PM Page viii Introducing Microsoft Dynamic HTML and HTC 199 HTC Structure 199 Building DHTML Applications 202 HTC Summary 205 Comparing XBL and HTC 206 Defining a Component 206 Adding Content 206 Event Handling 206 Attaching Components 207 JSF The Greatest Thing Since Sliced Bread 207 Cross Platform Support 208 Imagination As the Only Limit 209 A JSF Application Supporting Ajax XUL and HTC 209 Summary 211 ICHAPTER 5Loading Resources with Weblets 213 Introducing Resource Loading 213 Using Existing Solutions 214 Using Weblets 215 Exploring the Weblet Architecture 215 Using Weblets in Your Component Library 216 Using Weblets in a JSF Application 221 Summary 222 ICHAPTER 6Ajax Enabling the Deck Component 223 Requirements for the Deck Component s Ajax Implementation 223 The Ajax Enabled Deck Component 224 Designing the Ajax Enabled Deck Component Using a Blueprint 226 Step 1 Creating a UI Prototype 227 Step 4 Creating a Client Specific Renderer 230 Step 6 Registering a UIComponent and Renderer 238 Step 8 Creating a RenderKit and ResponseWriter 238 Step 9 Extending the JSF Implementation 249 Step 10 Registering the RenderKit and JSF Extension 262 Step 11 Registering Resources with Weblets 263 Summary 265 ICONTENTS ix 5807fm qxd 1 20 06 4 11 PM Page ix ICHAPTER 7Ajax Enabling the Date Field Component 267 Requirements for the Date Component s Ajax Implementation 267 The Ajax Enabled Date Component 268 Designing JSF Components Using a Blueprint 269 Step 1 Creating a UI Prototype 270 Step 4 Creating Converters and Validators 276 Step 5 Creating a Client Specific Renderer 279 Step 7 Registering a UIComponent and Renderer 297 Step 8 Creating a JSP Tag Handler and TLD 297 Step 12 Registering Your Ajax Resources with Weblets 301 Summary 301 ICHAPTER 8Providing Mozilla XUL Renderers 303 Requirements for the Deck and Date Components XUL Implementations 304 What Mozilla XUL Brings to JSF 304 What JSF Brings to XUL 304 The XUL Implementation of the Deck and Date Components 304 Designing JSF XUL Components Using a Blueprint 306 Step 1 Creating a UI Prototype 307 Step 3 Creating a Behavioral Superclass 322 Step 5 Creating a Client Specific Renderer 324 Step 6 Creating a Renderer Specific Subclass 341 Step 7 Registering a UIComponent and Renderer 345 Step 8 Creating a JSP Tag Handler and TLD 347 Step 9 Creating a RenderKit and ResponseWriter 350 Step 11 Registering a RenderKit 354 Step 12 Registering Resources with Weblets 355 Building Applications with JSF XUL Components 357 Summary 359 ICHAPTER 9Providing Microsoft HTC Renderers 361 Requirements for the Deck and Date Components HTC Implementations 362 What HTC Brings to JSF 362 What JSF Brings to HTC 362 ICONTENTSx 5807fm qxd 1 20 06 4 11 PM Page x The HTC Implementation of the Deck and Date Components 362 Designing JSF HTC Components Using a Blueprint 363 Step 1 Creating a UI Prototype 363 Step 5 Creating a Client Specific Renderer 380 Step 7 Registering a UIComponent and Renderer 396 Step 11 Registering a RenderKit and JSF Extension 396 Step 12 Registering Resources with Weblets 398 Building Applications with JSF HTC Components 398 Summary 401 ICHAPTER 10Switching RenderKits Dynamically 403 Requirements for Dynamically Switching RenderKits 404 The Dynamic RenderKit Implementation 405 Syntax for Dynamic RenderKit ID 405 The Dynamic RenderKit Managed Bean 406 The DynamicRenderKitViewHandler Class 409 Registering the Dynamic RenderKit Solution 411 Summary 412 IINDEX 413 ICONTENTS xi 5807fm qxd 1 20 06 4 11 PM Page xi 5807fm qxd 1 20 06 4 11 PM Page xii Foreword Does the world really and truly need another JavaServer Faces book I was fairly well convinced the answer could only be a resounding no After all there are a good half dozen books out in stores today by a whole host of Web luminaries and I ve even personally helped as a technical reviewer on half of those So what more could really be said on the subject But when I thought about this a bit more it became clear that all of these books go only so far They ll show you how to use what JSF gives you out of the box throw you a bone for writing your own components and renderers and give you maybe even a bit more But none that I ve seen get to the heart of why JSF is really and truly a cool and important technology they make JSF look like YAMVCF Yet Another Model View Controller Framework for HTML more pow erful here and there easier to use in many places a bit harder to use in others but really nothing major And certainly nothing that takes us beyond the dull basics of building ordinary looking Web applications This book goes a lot further It covers the basics of course and shows you how to build components but then it keeps going on to Ajax on to HTC on to XUL and how you can wrap up this alphabet soup underneath the heart of JSF its component model and how you can leverage it to finally develop Web applications that don t need radical rearchitecting every time the winds of client technologies blow in a different direction Along the way you ll learn a wide array of open source toolkits that make Web magic practical even when you re not a JavaScript guru So heck I m convinced The world does need another JSF book Adam Winer JSF Expert Group Member and Java Champion xiii 5807fm qxd 1 20 06 4 11 PM Page xiii 5807fm qxd 1 20 06 4 11 PM Page xiv About the Authors IJONAS JACOBI is a J2EE and open source evangelist at Oracle A native of Sweden Jonas has worked in the software industry for more than 15 years Prior to joining Oracle Jonas worked at several major Swedish software companies in management consulting development and project management roles For the past three years Jonas has been responsible for the product management of JavaServer Faces Oracle ADF Faces and Oracle ADF Faces Rich Client in the Oracle JDeveloper team Jonas is a popular speaker at international conferences such as Oracle OpenWorld EclipseWorld and JavaPolis and he has written numerous articles for leading IT magazines such as Java Developer s Journal JavaPro and Oracle Magazine Jonas has also contributed to the online appendix of JavaServer Faces in Action by Kito D Mann Manning 2005 and was a technical reviewer of Oracle JDeveloper 10g Handbook by Avrom Roy Faderman Peter Koletzke and Paul Dorsey McGraw Hill Osborne 2004 Apart from spending his spare time working on open source projects such as Weblets Mabon and D2 he likes golf sailing and fast cars preferably driving them he also enjoys spending time with his wife Marianne and his daughters Emma and Isabelle IJOHN R FALLOWS is a JavaServer Faces technology architect at Oracle Originally from Northern Ireland John graduated from Cambridge University in the United Kingdom and has worked in the software industry for more than ten years Prior to joining Oracle John worked as a research scientist for British Telecommunications Plc For the past four years John has played a leading role in the Oracle ADF Faces team to influence the architecture of the JavaServer Faces standard and to extend the standard to provide Ajax functionality in the ADF Faces project John is an active participant in the open source community contributing to both the Apache MyFaces project and the Apache Maven project John is also leading three new open source projects on J Weblets Mabon and D2 all of which evolved while researching the foundational technologies for this book Apart from spending his spare time writing articles about new and exciting technologies John likes to play soccer with his friends and likes to spend time with his beautiful wife Nan and their wonderful son Jack xv 5807fm qxd 1 20 06 4 11 PM Page xv 9d8d14ec8d289273f1d268bf63753ec7 5807fm qxd 1 20 06 4 11 PM Page xvi About the Technical Reviewers IPETER LUBBERS is an information architect at Oracle A native of the Netherlands Peter served as a Special Forces commando in the Royal Dutch Green Berets Prior to joining Oracle Peter architected and devel oped the internationalized Microsoft Office User Specialist MOUS testing framework At Oracle Peter develops automated help authoring solutions Three of these solutions are currently patent pending He is also the author of the award winning Oracle Application Server Portal Configuration Guide Oracle 2005 IKITO D MANN is the editor in chief of JSF Central and the author of JavaServer Faces in Action Manning 2005 He is also a member of the JSF 1 2 and JSP 2 1 expert groups and principal consultant at Virtua specializing in enterprise application architecture development men toring and JSF product strategy Kito has consulted with several Fortune 500 clients including Prudential Financial and J P Morgan Chase if I ve missed someone you have my heartfelt apologies I would first like to thank my good friend Peter Z d for letting me in on the how to make your family happy when writing a book secret and for always being there whenever I had doubts about this project To a true friend John R Fallows I don t think my vocabulary has enough superlatives to describe my coauthor and colleague I will be forever in his debt for all the knowledge I pulled out of him during long hours and for the patience and dedication he brought to this project without John this would not have been possible To the most important person in my life my wonderful wife Marianne without whom I wouldn t have been able to complete this book To my beautiful daughters Emma and Isabelle for patiently waiting for me to come home and play Jonas Jacobi xix 5807fm qxd 1 20 06 4 11 PM Page xix I would first like to thank my very good friend and coauthor Jonas Jacobi for proposing that we work on this book together Jonas has my deepest respect for his ability to consume highly detailed architectural knowledge and simplify it for the reader in a practical and entertaining way There is no doubt that without Jonas this book would simply not have been possible To my amazing wife Nan whose endless patience and support made it possible for me to work on this book while she was pregnant with our son Jack and for the first six months of his life To my son Jack for those lovable deep laughs that made me smile no matter how tired I was To my dad for always encouraging me to reach for the stars John R Fallows IACKNOWLEDGMENTSxx 5807fm qxd 1 20 06 4 11 PM Page xx Introduction Since JavaServer Faces first arrived on the Internet technology stage as the new standard for building Java based Web applications it has gained significant attention from the Java EE Web development community Many developers are excited that they can use the standard JavaServer Faces HTML Basic RenderKit to create HTML based Web applications much as they did in the past with other technologies such as Apache Struts However this is only the tip of the iceberg the true power of JavaServer Faces lies in its extensible component model which allows you to go far beyond those humble HTML beginnings Based on the recent surge in demand for improved usability in Web applications it is understandable that the hottest topic at the moment is Rich Internet Applications RIAs and how they offer distributed server based Web applications with a rich interface and the inter action capabilities of desktop applications Although RIAs hold significant promise they still have issues with compatibility portability usability and reusability Many Web application developers are struggling to keep up with new RIA frameworks both open source and vendor specific as they appear on the market What is needed is a standard way of defining an RIA regardless of what RIA framework is being used The debate over the best way to develop and deploy RIAs will not end with this book but looking at the software industry today more and more developers are using the Web to deploy their applications User interfaces for these Web applications are often built with technologies such as HTML CSS JavaScript and the DOM These technologies were not developed with enterprise applica tions in mind and with an increasing pressure from consumers to provide applications with features not fully described or supported by these technologies developers are looking for alternative solutions or to extend the standards JSF does not just let you pick a single RIA technology such as Ajax Mozilla XUL Microsoft HTC Macromedia Flash and so on it lets you pick and combine any RIA technologies you want and use them where they make the most sense As with any technology each RIA tech nology has its own advantages and disadvantages but as a JSF component writer you have the opportunity to leverage the best functionality of each RIA technology to provide the appli cation developer with an extremely powerful RIA solution We have been very much involved in the development and the use of component based frameworks over the past five years starting with Oracle s own UI component framework ADF UIX and lately with Oracle s JSF component library ADF Faces One day a very good friend asked us Why don t you guys share some of your experience and write a book about it What surprised us was that nobody had actually written a book targeting developers who are interested in the same thing we are how to develop reusable standards based JSF components for RIAs So here we are hoping that you will enjoy reading this book as much as we enjoyed writing it xxi 5807fm qxd 1 20 06 4 11 PM Page xxi An Overview of This Book Pro JSF and Ajax Building Rich Internet Components is written to give you all the means to provide your Web application developers with easy to use Rich Internet Components RICs We decided early on that we would focus on establishing a clear blueprint that you as a devel oper could follow to be successful in your own JSF component development We also decided that we would not limit this book to just JSF components and that we would incorporate everything you would need to know to be successful in developing packaging and deploying your own RICs This book is not and we would like to emphasize this not an introductory level book about JSF or about writing simple JSF components Sure this book introduces JSF and covers the basics of writing JSF components but if you have not acquainted yourself with JSF before reading this book we strongly encourage you to refer to a few excellent books that will introduce you to JSF and give you the foundation needed to fully appreciate this book We recommend JSF in Action by Kito D Mann Manning 2005 which is an excellent and very complete book on JSF and Core JavaServer Faces

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值