What readers are saying about Mastering Dojo
I’m so glad to see this book released. Dojo has a lot of power, but
there’s also a lot of complexity to knowing which API methods to use
when, and how to use them, and this book goes beyond just explain-
ing the Dojo API to explaining what developers need to know to use it
effectively.
Bill Keese
Project lead for Dijit
IBM, Emerging Technology Group
Mastering Dojo will teach you how to build an Internet application
that will impress your end users and delight you while you’re writing
it. The book also explains Dojo’s JavaScript underpinnings, both for
newcomers and for refugees from other languages.
Ian Dees
Software engineer
The book really rolls out the red carpet for Dojo to emerge with guns
blazing! The authors show you how easy it is to use impressive
widgets without installing a thing. I was amazed to discover that
JavaScript is not just a toy language, how Dojo is built on top of it,
and how both are invaluable in any web development project. Buy
this book. It’s the next best thing to having the authors working at
your side.
Brian C. Reeve
Application developer, bluecomIT.com
Mastering Dojo is an understandable, in-depth guide to learni ng the
Dojo Toolkit. It’s a great supplement to the Dojo Toolkit’s online docu-
mentation.
Steve Orvell
Senior Engineer, WaveMaker Software
Masterin g Dojo
JavaScript and Ajax Tool s
for Great Web Experiences
Rawld Gill
Craig Riecke
Alex Russell
The Pragmatic Bookshelf
Raleigh, North Carolina Dallas, Texas
Many of the designations used by manufacturers and sellers to distinguish their prod-
ucts are claimed as trademarks . Where those designations appear in this book, and The
Pragmatic Programmers, LLC wa s aware of a trademark claim, the designations have
been printed in initial capital letters or in all capitals . The Pragmatic Starter Kit, The
Pragmatic Programmer, Pragmatic Programming, Pragmatic Bookshelf and the linking g
device are trademarks of The Pragmatic Programmers, LLC.
The Brow ser Application Framework code is Copyright
©
2000-2008, Vista Information
Technologies, Inc., and released under the BSD license.
Every precaution wa s taken in the preparation of this book. However, the publisher
assumes no responsibility for errors or omissions, or for damages that may result from
the use of information (including program listings) contained herein.
Our Pragmatic courses, workshops, and other products can h elp you and your team
create better software and have more fun. For more information, as well as the late st
Pragmatic titles, please visit us at
http://www.pragprog.com
Copyright
©
2008 Rawld Gill, Craig Riecke and Alex Russell.
All rights reserved.
No part of this publication may be reproduced, stored in a retrieval system, or trans mit-
ted, in any form, or by an y mea ns, electronic, mecha nical, photocopying, recording, or
otherwise, without the prior consent of the publisher.
Printed in the United States of America.
ISBN-10: 1-934356-11-5
ISBN-13: 978-1-934356-11-1
Printed on acid-free paper with 50% recycled, 15% post-consumer content.
Contents
1 Introduction 9
1.1 Key Aspects of Dojo . . . . . . . . . . . . . . . . . . . . . 12
1.2 Using the Book . . . . . . . . . . . . . . . . . . . . . . . 15
1.3 Acknowledgments . . . . . . . . . . . . . . . . . . . . . . 17
I Ajax the Dojo Way 19
2 Powerful Web Forms Made Easy 20
2.1 What Customers Are Saying About Your Form . . . . . 21
2.2 Installing Dojo on Your Own Server . . . . . . . . . . . . 21
2.3 Adding Dojo and Dijit to a Page . . . . . . . . . . . . . . 22
2.4 Laying Out the Form . . . . . . . . . . . . . . . . . . . . 26
2.5 Improved Form Controls . . . . . . . . . . . . . . . . . . 31
2.6 Wrapping It Up . . . . . . . . . . . . . . . . . . . . . . . 34
3 Connecting to Outside Services 37
3.1 Dojo Remote Scripting . . . . . . . . . . . . . . . . . . . 37
3.2 JavaScript Idioms for Calling XHR . . . . . . . . . . . . 39
3.3 A Wish List w i th dojo.data and dojox.grid.Grid . . . . . . 46
3.4 Researching Cigars Using JSONP . . . . . . . . . . . . . 56
3.5 Reviews with dojo.xhrGet . . . . . . . . . . . . . . . . . 63
3.6 Errors and Debugging . . . . . . . . . . . . . . . . . . . 67
II The Dojo APIs 70
4 Dojo In Depth 71
4.1 Modularizing JavaScript . . . . . . . . . . . . . . . . . . 71
4.2 Dojo Source Code Organization . . . . . . . . . . . . . . 75
4.3 Loading Dojo . . . . . . . . . . . . . . . . . . . . . . . . . 78