Pro Ajax Java
Total Page:16
File Type:pdf, Size:1020Kb
CYAN YELLOW MAGENTA BLACK PANTONE 123 CV EMPOWERING JAVA DEVELOPERS WITH AJAX TECHNIQUES THE EXPERT’S VOICE® IN WEB DEVELOPMENT Companion eBook Available Pro Ajax and Java Pro Ajax Dear Reader, If you are a professional Java developer and you want to know how best to go about adding Ajax functionality to your web applications to enrich your users’ experience, then Pro Ajax and Java is the right book for you. Ajax allows us to Nathaniel T. Schutta, build highly interactive, desktop-like web applications that can be deployed coauthor of through any modern web browser without the need for special plug-ins. Though Foundations of Ajax Ajax is server-side agnostic, it certainly plays well within the rich Java ecosystem. This book teaches you what you need to know by using tightly focused exam- ples that aren’t cluttered with extraneous details, putting you on the fast track to using Ajax in your own Java applications. You already know how to develop web applications, so this book focuses on teaching the killer techniques you’ll need to bring your applications to life with Ajax, including autocomplete, form vali- dation, dynamic visual effects, and much, much more. We start off by providing a brief summary of the subject area, followed by a and Pro Ajax guide to creating the perfect development environment for developing Ajax in Java, including code editing and formatting, DOM inspection, debugging, Ryan Asleson, coauthor of testing, and logging tools. Foundations of Ajax Next, we look in depth at the most popular Ajax libraries and toolkits avail- able, and what they can do to simplify and speed up our Ajax development— Java Prototype, script.aculo.us, Dojo, DWR, AjaxTags, and Taconite. In the final RELATED TITLE section, we explore Ajax development within four of the most popular Java Practical Ajax Projects frameworks—Spring, Struts, Tapestry, and JSF. with Java Thanks for picking up this book. We hope you’ll have as much fun reading it as we had writing it! and Java Nate Schutta and Ryan Asleson Join online discussions: forums.apress.com FOR PROFESSIONALS BY PROFESSIONALS™ THE APRESS PRO AJAX AND JAVA ROADMAP Covers everything Java developers need Beginning JavaScript with Companion eBook Ajax Patterns to know to add Ajax to their websites! DOM Scripting and Ajax: and Best Practices From Novice to Professional Pro JavaScript Techniques Beginning Pro JSF and Ajax: CSS Web Development Building Rich From Novice to Professional Internet Components See last page for details Foundations of Ajax on $10 eBook version Beginning POJOs Pro Ajax and Java Asleson Schutta, SOURCE CODE ONLINE Nathaniel T. Schutta and Ryan Asleson www.apress.com ISBN 1-59059-677-3 54999 US $49.99 Shelve in Java Programming User level: Intermediate–Advanced 6 89253 59677 7 9 781590 596777 this print for content only—size & color not accurate spine = 0.784" 336 page count Asleson _677-3FRONT.fm Page i Tuesday, June 20, 2006 6:58 AM Pro Ajax and Java ■■■ Nathaniel T. Schutta and Ryan Asleson Asleson _677-3FRONT.fm Page ii Tuesday, June 20, 2006 6:58 AM Pro Ajax and Java Copyright © 2006 by Nathaniel T. Schutta and Ryan Asleson 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 (pbk): 978-1-59059-677-7 ISBN-10 (pbk): 1-59059-677-3 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: Chris Mills Technical Reviewer: John R. Fallows Editorial Board: Steve Anglin, Ewan Buckingham, Gary Cornell, Jason Gilmore, Jonathan Gennick, Jonathan Hassell, James Huddleston, Chris Mills, Matthew Moodie, Dominic Shakeshaft, Jim Sumser, Keir Thomas, Matt Wade Project Manager: Richard Dal Porto Copy Edit Manager: Nicole LeClerc Copy Editor: Hastings Hart Assistant Production Director: Kari Brooks-Copony Production Editor: Laura Esterman Compositor: Susan Glinert Proofreader: April Eddy Indexer: Lucie Haskins Artist: Susan Glinert 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 [email protected], or visit http://www.springeronline.com. 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 [email protected], or visit http://www.apress.com. 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. The source code for this book is available to readers at http://www.apress.com in the Source Code section. Asleson _677-3FRONT.fm Page iii Tuesday, June 20, 2006 6:58 AM To Christine, for always believing. —Nathaniel T. Schutta For Sara, the love of my life, and Adam, my favorite playmate. —Ryan Asleson Asleson _677-3FRONT.fm Page iv Tuesday, June 20, 2006 6:58 AM Asleson _677-3FRONT.fm Page v Tuesday, June 20, 2006 6:58 AM Contents at a Glance About the Authors . .xi About the Technical Reviewer . xiii Acknowledgments . xv Introduction . xvii PART 1 ■ ■ ■ Introducing Ajax ■CHAPTER 1 What Is Ajax? . 3 ■CHAPTER 2 Development Tools . 27 PART 2 ■ ■ ■ Libraries and Toolkits ■CHAPTER 3 Java-Agnostic Toolkits . 75 ■CHAPTER 4 Java-Specific Frameworks . 117 PART 3 ■ ■ ■ Web Frameworks ■CHAPTER 5 Struts and Ajax . 153 ■CHAPTER 6 Tapestry . 183 ■CHAPTER 7 Spring and Ajax . 219 ■CHAPTER 8 JavaServer Faces . 263 ■INDEX . 297 v Asleson _677-3FRONT.fm Page vi Tuesday, June 20, 2006 6:58 AM Asleson _677-3FRONT.fm Page vii Tuesday, June 20, 2006 6:58 AM Contents About the Authors . .xi About the Technical Reviewer . xiii Acknowledgments . xv Introduction . xvii PART 1 ■ ■ ■ Introducing Ajax ■CHAPTER 1 What Is Ajax? . 3 The Rise of the Web Application . 3 And Then There Was Ajax . 5 The XMLHttpRequest Object . 9 Methods and Properties . 12 An Example Interaction . 13 Avoiding Common Gotchas . 16 Ajax Patterns . 20 The Fade Anything Technique (FAT) . 21 Auto Refresh . 22 Partial Page Paint . 22 Draggable DOM. 23 Summary . 25 ■CHAPTER 2 Development Tools . 27 JavaScript Source Code Editor . 27 JSEclipse . 28 NetBeans JavaScript Plug-in. 32 JavaScript Compression and Obfuscation . 35 The Dojo Toolkit’s JavaScript Compressor . 37 Inspecting a DOM Structure . 38 Mouseover DOM Inspector . 39 Debugging Ajax Requests . 40 NetBeans HTTP Monitor . 41 Firefox FireBug Extension . 43 vii Asleson _677-3FRONT.fm Page viii Tuesday, June 20, 2006 6:58 AM viii ■CONTENTS JavaScript Logging . 45 Log4JS . 46 Lumberjack . 49 JavaScript Debugging Tools . 52 Using Venkman . 52 Testing Tools . 56 JsUnit . 57 Selenium . 58 Summary . 71 PART 2 ■ ■ ■ Libraries and Toolkits ■CHAPTER 3 Java-Agnostic Toolkits . 75 Prototype . 75 $() . 76 Working with Forms . 77 Manipulating the DOM . ..