DWR Java AJAX Applications A step-by-step example-packed guide to learning professional application development with Direct Web Remoting Sami Salkosuo BIRMINGHAM - MUMBAI This material is copyright and is licensed for the sole use by Henry Vanyan on 26th July 2009 7406 Valaho Dr, , Tujunga, , 91042 DWR Java AJAX Applications Copyright © 2008 Packt Publishing All rights reserved. No part of this book may be reproduced, stored in a retrieval system, or transmitted in any form or by any means, without the prior written permission of the publisher, except in the case of brief quotations embedded in critical articles or reviews. Every effort has been made in the preparation of this book to ensure the accuracy of the information presented. However, the information contained in this book is sold without warranty, either express or implied. Neither the author, Packt Publishing, nor its dealers or distributors will be held liable for any damages caused or alleged to be caused directly or indirectly by this book. Packt Publishing has endeavored to provide trademark information about all the companies and products mentioned in this book by the appropriate use of capitals. However, Packt Publishing cannot guarantee the accuracy of this information. First published: October 2008 Production Reference: 1151008 Published by Packt Publishing Ltd. 32 Lincoln Road Olton Birmingham, B27 6PA, UK. ISBN 978-1-847192-93-6 www.packtpub.com Cover Image by Parag Kadam ([email protected]) Download at Boykma.Com This material is copyright and is licensed for the sole use by Henry Vanyan on 26th July 2009 7406 Valaho Dr, , Tujunga, , 91042 Credits Author Editorial Team Leader Sami Salkosuo Mithil Kulkarni Reviewers Project Manager Jason Crow Abhijeet Deobhakta Matthew Henry Sujit Pal Project Coordinator Rajashree Hamine Acquisition Editor Adil Ahmed Indexer Rekha Nair Development Editor Usha Iyer Proofreader Chris Smith Technical Editor Darshana D. Shinde Production Coordinator Rajni R. Thorat Copy Editor Sumathi Sridhar Cover Work Rajni R. Thorat Download at Boykma.Com This material is copyright and is licensed for the sole use by Henry Vanyan on 26th July 2009 7406 Valaho Dr, , Tujunga, , 91042 About the Author Sami Salkosuo is a Software IT Architect at IBM Software Group, Finland. He has over ten years of experience in Java, Web, and integration technologies. Sami has written several articles for IBM developerWorks, and is also the co-author of an IBM Redbook: Portalizing Domino Applications. I am thankful to the reviewers Sujit Pal, Matthew Henry, and Jason Crow for their comments that helped me improve my writing. My thanks to Rajashree Hamine, Usha Iyer, Darshana Shinde, and others at Packt Publishing for making this book come true. My sincere thanks also for my family for their patience and support. Download at Boykma.Com This material is copyright and is licensed for the sole use by Henry Vanyan on 26th July 2009 7406 Valaho Dr, , Tujunga, , 91042 About the Reviewers Jason Crow is the lead Java Developer for Office Depot, Inc. in Delray Beach, Florida. He specializes in blending his expertise in Java, DWR, HTML, CSS, and jQuery to enhance usability and to bring dynamic features to officedepot.com. He actively contributes back to the community through his blog http://greatwebguy.com. Matthew Henry is the Programming Services Manager at LeTourneau University. Matthew has worked in IT and computer related fields as a programmer for 30 years. Matthew co-authored Upgrading to Lotus Notes 7 and has written various articles for specific computer industry magazines. Sujit Pal started programming some 20 years ago, and has never looked back since. He currently works at Healthline Networks, Inc., a search vertical focused on health, as part of its Research and Development team. Apart from his work, his favorite pastime is to explore new software technologies, techniques, and languages, and he writes about his experiments at sujitpal.blogspot.com. Download at Boykma.Com This material is copyright and is licensed for the sole use by Henry Vanyan on 26th July 2009 7406 Valaho Dr, , Tujunga, , 91042 Download at Boykma.Com This material is copyright and is licensed for the sole use by Henry Vanyan on 26th July 2009 7406 Valaho Dr, , Tujunga, , 91042 Table of Content Preface 1 Chapter 1: Introduction 7 What is AJAX? 7 DWR: AJAX for Java Developers 9 The DWR Community 11 Summary 12 Chapter 2: DWR Features 13 Ease of Use 14 Reverse AJAX 14 Piggyback 14 Polling 15 Comet 16 DWR JavaScript Libraries 18 engine.js 19 util.js 20 gi.js 23 Converters 23 Creators, Filters, and Signatures 24 Integration with Other Projects 25 Security 26 Minimize Risks 27 Summary 28 Chapter 3: Getting Started 29 Supported Browsers and Environments 30 Configuration 30 web.xml 30 dwr.xml 32 Using Creator and Its Attributes 33 Download at Boykma.Com This material is copyright and is licensed for the sole use by Henry Vanyan on 26th July 2009 7406 Valaho Dr, , Tujunga, , 91042 Table of Contents Using the Converter Element 34 Working with Annotations 35 Using Fluent Configuration with DWR 36 Setting up a Development Environment 37 Development Environment with DWR and Firefox 37 Development Environment with Eclipse 37 Apache Geronimo 41 Testing and Debugging 41 Error Handling 42 Packaging and Deployment 44 Deployment Using the Administration Console 47 Deployment Using the Deployer Tool 50 Deployment Using Hot Deployment 51 Summary 51 Chapter 4: User Interface: Basic Elements 53 Creating a Dynamic User Interface 53 Creating a New Web Project 55 Configuring the Web Application 57 Developing the Web Application 59 Testing the Web Application 60 Developing Web Pages 64 Callback Functions 69 Afterword 70 Implementing Tables and Lists 71 Server Code for Tables and Lists 72 Client Code for Tables and Lists 79 Testing Tables and Lists 85 Afterword 87 Implementing Field Completion 87 Server Code for Field Completion 88 Client Code for Field Completion 89 Afterword 95 Summary 95 Chapter 5: User Interface: Advanced Elements 97 Creating Forms 97 Developing the User Interface 98 Creating the FormHandler Class 101 Testing the Form 103 Afterword 106 Building a Navigation Tree 106 Developing the User Interface 106 [ ii ] Download at Boykma.Com This material is copyright and is licensed for the sole use by Henry Vanyan on 26th July 2009 7406 Valaho Dr, , Tujunga, , 91042 Table of Contents Creating the NavigationTree Class 108 Developing the User Interface, Part 2 110 Testing the Navigation Tree 113 Afterword 115 Map Scrolling Using DWR 115 Developing the User Interface 117 Creating the MapScroller Java Class 124 Testing the Map Scroller 126 Afterword 129 Summary 129 Chapter 6: Backend Integration 131 Integrating a Database with DWR 131 Configuring the Database in Geronimo 132 Creating a CountryDerbyDB Java Class 138 Testing the Database Integration 142 Afterword 143 Integrating with Web Services 143 Developing the Web Service Client 144 Implementing the Web Service Call 151 Testing Web Services Integration 152 Afterword 153 Integrating with a Messaging System 153 Setting up Queues in Geronimo 154 Developing the OrderSystem Java Class 158 Setting up the Application for Messaging 161 Testing with the Backend OrderSystem 163 Afterword 165 Summary 165 Chapter 7: Sample Applications 167 Collaborative Book Authoring 167 Starting the Project 168 Developing the User Interface 168 index.jsp 170 loginFailed.html 171 mainpage.jsp 171 Configuring the Web Application 182 Developing the Java Classes 184 Login.java 184 UserDatabase.java 186 Util.java 187 Book.java 188 BookDatabase.java 190 [ iii ] Download at Boykma.Com This material is copyright and is licensed for the sole use by Henry Vanyan on 26th July 2009 7406 Valaho Dr, , Tujunga, , 91042
Description: