APPENDIX A ■ ■ ■ The XMLHttpRequest Object

More often than not, chances are you will use some sort of to do your work. Some of the libraries out there—only a handful of which we talked about in this book—really do make it far easier to work the “Ajax way.” That being said, there are times when you will want to go “bare metal,” so to speak, and use the XMLHttpRequest object yourself. In those instances, this appendix will be an invaluable aid to you.

What Is the XMLHttpRequest Object? XMLHttpRequest is an object (an ActiveX object in Microsoft Explorer, a native component in most other browsers) that allows a to make a request to a and get a response back without reloading the entire page. The user remains on the same page, and more important, they will not actually see the processing occur—that is, they will not see a new page loading, not by default at least. Using the XMLHttpRequest object makes it possible for a developer to alter a page previously loaded in the browser with data from the server without having to request the entire page from the server again.

What Browsers Support the XMLHttpRequest Object? XMLHttpRequest is present in 5.0 and higher, Apple’s 1.2 and higher, ’s 1.0 and higher, 7.6 and higher, and 7 and higher. Other browsers may or may not support it, so you should check for the capability before attempting to use it if you intend to support alternative browsers. Also of note is a little JavaScript library by Andrew Gregory that allows for cross-browser Ajax support without dealing with the details of what browsers support the object and how. There are some limitations, but it is of interest nonetheless. You can find information on it here: www.scss.com.au/family/andrew/webdesign/xmlhttprequest.

479 480 APPENDIX A ■ THE XMLHTTPREQUEST OBJECT

Is the XMLHttpRequest Object a W3C Standard? (Or Any Other Kind of Standard for That Matter!) No, the XMLHttpRequest object is not a W3C standard, or a standard of any other standards body. The W3C DOM Level 3 specification’s “Load and Save” capabilities would provide similar functionality, but currently no browsers implement the Level 3 specification. Therefore, until that specification is widely adopted, if you need to send an HTTP request from a browser and get a response from a server, aside from the normal page navigation mechanism, the XMLHttpRequest object is the only viable option, along with some of the lesser-used (nowadays) alternatives like Java applets and ActiveX controls.

How Do I Use the XMLHttpRequest Object? In Mozilla, Firefox, Safari, and Netscape, you create an instance of the XMLHttpRequest object by doing the following:

For Internet Explorer:

Here is an example of using the XMLHttpRequest object:

XMLHttpRequest Object Method and Properties Reference Tables A-1 and A-2 outline the methods and properties available on the XMLHttpRequest object, representing the full API interface to that object through which you will interact with it.

Table A-1. XMLHttpRequest Object Methods Method Description abort() Stops the request that the object is currently processing. Note that like clicking the Stop button in your browser, the server will not be notified and will continue to process the request. getAllResponseHeaders This method returns all of the headers, both keys and values, as a string. getResponseHeader("key") This method returns the specified header value as a string. open("method", "url" [,asyncFlag Contrary to its name, this does not appear to literally [,"username" [,"password"]]] open anything. Instead, it just sets the parameters for the pending request. The value of method may be any valid HTTP method, get and being the most common. asyncFlag is either true or false. Setting this to false will cause all JavaScript on the page to halt until the request returns. This is generally not desirable because if the server is unavailable, or the operation simply takes a long time, the will seem to freeze to the user. Use with caution! username and password are used to make requests to protected with Basic Auth security. Note that these two parameters, as well as asyncFlag, are optional, while method and url are required. send(content) This method transmits the pending request, and optionally sends a POST body or serialized DOM object (i.e., XML document). If POSTing simple parameters, content should be a string in the “name1=value1&name2=value2”—in other words, a query string minus the initial question mark. setRequestHeader("key", "value") Sets an HTTP header that will be set on the outgoing response. 482 APPENDIX A ■ THE XMLHTTPREQUEST OBJECT

Table A-2. XMLHttpRequest Object Properties Property Description onReadyStateChange This is a pointer to the function that will serve as the event handler for the request this object instance is processing. Note that this function will be called multiple times during the lifecycle of the request. readyState This is an integer representing the status of the request. Possible values are 0 (uninitialized), 1 (loading), 2 (loaded), 3 (interactive), and 4 (complete). responseText This is a textual string version of the response from the server. Even if the response was XML, you will still find the actual text of the response here. responseXML If the response from the server was XML, the object will do the extra work of parsing it and generating a real DOM-compatible object that you can manipulate with DOM methods. status This is the numeric HTTP result code returned by the server, such as 404 if the resource is not found, or 200 if the result was OK. statusText This is a textual message string describing the status code.

XMLHttpRequest Object Status Codes Table A-3 lists the status codes that can show up in the readystate field of the XMLHttpRequest object during the lifecycle of a request as your callback function is repeatedly called.

Table A-3. XMLHttpRequest Object readystate Status Codes Numeric Code Description 0 Uninitialized. This is the value the readystate field will have initially before any operation is begun. 1 Loading. This means the open() method has been successfully called, but send() has not yet been called. 2 Loaded. This means send() has been called, and the object has completed the request, but no data has been received yet. Headers and status, however, are available at this point. 3 Receiving (or Interactive). This means the response is being chunked back to the . responseText at this point will hold the response as received thus far. 4 Loaded (or Completed). The request has completed and the full response has been received. APPENDIX B ■ ■ ■ Libraries, , and Books, Oh My!

Throughout this book, we’ve referenced a number of libraries, websites, and books for you to get further information or see examples. Here is a concise list of all those references for your convenience, even for those libraries that are used as part of an application but not specifi- cally described (but, uh, please do still read this book, OK?).

Libraries/Toolkits/Products

• Adobe (formerly Macromedia) Flash (www.adobe.com/products/flash/flashpro): Flash is not just a vector animation tool; it is truly a full-fledged development environment allow- ing you to create multimedia-rich websites that will run identically across most modern platforms (if a supported Flash player is available, which is mostly the case these days).

• Adobe (formerly Macromedia) Flex (www.adobe.com/flex): A rich client development framework that can greatly simplify creation of dynamic web applications.

• Apache Ant (ant.apache.org): The de facto standard in Java build tools.

(geronimo.apache.org): An Apache .

• Apache Jakarta Commons (jakarta.apache.org/commons): Under the Commons banner you will find a number of very useful libraries, including Commons Logging, BeanUtils, FileUpload, Commons Chain, and much more. In short, if you aren’t using Commons today, you should be tomorrow!

• BEA WebLogic (www.bea.com): Another of the big players in the application server mar- ket; provides much the same capabilities as WebSphere (although both vendors have their advantages and disadvantages).

• Caucho’s (www.caucho.com): Another application server, fairly popular with web hosts.

• Dojo (dojotoolkit.org): A popular Ajax toolkit that, in addition to its Ajax functionality, provides a lot of nifty client-side functions such as collections and client-side session storage, as well as a number of excellent GUI widgets.

483 484 APPENDIX B ■ LIBRARIES, WEBSITES, AND BOOKS, OH MY!

• DWR, or Direct Web Remoting (getahead.ltd.uk/dwr): A very popular Ajax library that provides a syntax in JavaScript to call objects on the server, making them appear to be running locally (in terms of the JavaScript you write).

• Eclipse (www.eclipse.org): Probably the most popular Java IDE out there, and free to boot!

• FreeMarker (freemarker.sourceforge.net): A Java-based template engine, used by default by WebWork.

• HSQLDB (www.hsqldb.org): Free, lightweight (but not in terms of functionality!), pure- Java engine.

• IBM WebSphere (www-306..com/software/websphere): A full-blown Java application server providing many services, including servlets, JSP, JNDI, EJB, and so on.

• IntelliJ IDEA (www.jetbrains.com/idea): If you want an IDE and don’t mind paying for it, this is probably the best available.

• Java Web Parts (javawebparts.sourceforge.net): A collection of handy classes and utili- ties such as servlets, filters, taglibs, a Chain of Responsibility (CoR) implementation, and much more, to help web developers working in Java.

• jEdit (www.jedit.org): A fantastic , this one is free and open source, and more important, features a large number of plug-ins that perform a great deal of tasks, bring- ing it closer to a full-blown IDE than just a text editor.

(http://mortbay.org/jetty/index.html): Jetty is a 100 percent Java HTTP server and servlet container. This means that you do not need to configure and run a separate (like Apache) in order to use Java, servlets, and JSPs to generate dynamic content.

• JSLib (http://jslib.mozdev.org): A JavaScript library from the Mozilla Foundation that includes such features as an SAX XML parser.

• JSTL (java.sun.com/products/jsp/jstl): JavaServer Pages Standard Library, a set of simple, common tags to be used in JSPs to make your life easier and your pages cleaner.

• Macromedia JRun (www.macromedia.com/software/jrun): Another entry in the server market.

• Maven (maven.apache.org): An increasingly popular build tool, Maven is designed to do most things for you without you having to write build scripts as you do with Ant.

• OpenEJB (http://sourceforge.net/projects/openejb): An open source, modular, con- figurable, and extendable Enterprise JavaBeans (EJB) container system and EJB server.

• Prototype (prototype.conio.net): JavaScript library for doing Ajax, as well as some other handy things.

• ROME (://rome.dev.java.net): A Java library for working with RSS feeds.

• Sarissa (http://sourceforge.net/projects/sarissa): Billed as a general-purpose XML processing tool for JavaScript, it includes XSLT processing and much more. APPENDIX B ■ LIBRARIES, WEBSITES, AND BOOKS, OH MY! 485

(www.springframework.org): A massive framework that covers a great many of the bases J2EE developers need, including an Inversion of Control (IoC) con- tainer, Aspect-Oriented Programming (AOP) support, and JDBC utility classes.

• Struts Action Framework (struts.apache.org): Perhaps the most popular web - work out there utilizing the Model-View-Controller (MVC) pattern.

• Tomcat (tomcat.apache.org): The reference implementation of the servlet and JSP specs, Tomcat is a fast, simple, standards-compliant, and powerful servlet container favored by many developers and hosting environments alike.

• UltraEdit (www.ultraedit.com): In my opinion, the best text editor available for Windows.

• Velocity (jakarta.apache.org/velocity): A Java-based template engine; an alternative to JSPs.

• WebWork (www.opensymphony.org/webwork): A popular MVC framework, which is, as of this writing, the future of Struts.

• Xara Webstyle (www.xara.com/products/webstyle/): For those of us who can do some graphics work but are far from artists ourselves, Webstyle is a fantastic tool to create graphics for the Web that make us look like we know what we’re doing!

• XML4Script (http://xmljs.sourceforge.net/website/documentation-w3cdom.html): Another JavaScript library for parsing XML.

Websites

• Adaptive Path (www.adaptivepath.com): The company that Jesse James Garrett works for.

• “Ajax: A New Approach to Web Applications,” by Jesse James Garrett (www.adap- tivepath.com/publications/essays/archives/000385.): The article where Ajax got its name.

• BackBase (www.backbase.com): Providers of excellent Ajax applications and toolkits.

• CSS Zen Garden (www.csszengarden.com): If you want to see what is possible with CSS layout, look no further than this site.

• Excite (www.excite.com): A great example of a portal site.

• Flickr (www.flickr.com): Ajax-enabled photo sharing.

• Fotki (www.fotki.com): Another Ajax-enabled photo-sharing site.

• Google Maps (maps.google.com): One of the Ajax applications that brought the tech- nique to the attention of developers the world over.

• Google Suggest (www.google.com/webhp?complete=1&hl=en): Probably the most famous example of a type-ahead Ajax application. 486 APPENDIX B ■ LIBRARIES, WEBSITES, AND BOOKS, OH MY!

• Google’s GMail (gmail.google.com): One of the other great examples of Ajax usage from Google.

• Google’s RSS reader (www.google.com/reader): A web-based RSS reader from Google utilizing Ajax.

• iBiblio (www.ibiblio.org): iBiblio has a modest goal: to back up the entire Internet! Well, that might be exaggerating a bit, but it is billed as a public library and archives. Most important for the purposes of this book is the Maven repository (www.ibiblio.org/maven) they maintain, where many of the most popular open source libraries and toolkits can be downloaded automatically by Maven as well as Ant scripts.

• The JSON home page (http://json.org): All about JavaScript Object Notation (JSON).

• Mappr (www.mappr.com): An excellent example of a Flash site done well.

• MSNBC (www.msnbc.com): The of the news channel MSNBC.

• Num Sum (www.numsum.com): An Ajax-based spreadsheet.

• OpenSymphony (http://opensymphony.com): An organization, along the lines of Apache, that supplies a number of open source products, including WebWork and XWork.

• PBase (www.pbase.com): Yes, yet another Ajax-enabled photo-sharing site.

• Prototype documentation by Sergio Pereira (www.sergiopereira.com/articles/ prototype.js.html#Enumerating).

• Shadow Gallery (www.shadowgallery.com): One of the bands I have made reference to in this book. Check them out—you’ll love them!

• Slashdot (www.slashdot.org): News for nerds, stuff that matters!

• Sun (http://java.sun.com): The place for all things Java.

• W3Schools (www.w3schools.com): An excellent all-around reference site for all things HTML. You can learn about CSS, HTML, DOM scripting, and even Ajax itself there.

• WebShots (www.webshots.com): Another Ajax-enabled photo-sharing site.

• Wikipedia (www.wikipedia.com): The free, online dictionary that everyone can help make better!

• Yahoo! (www.yahoo.com): One of the oldest search sites around; now they do just about everything.

Books

• Beginning CSS Web Development: From Novice to Professional, by Simon Collison. An excellent book to get your CSS knowledge up to snuff (Apress, 2006). APPENDIX B ■ LIBRARIES, WEBSITES, AND BOOKS, OH MY! 487

• Beginning JavaScript with Ajax and DOM Scripting: From Novice to Professional, by Chris Heilmann. A great book for JavaScript and Ajax novices, with a slightly different scope than Jeremy Keith’s book (Apress, 2006).

• Beginning XML with DOM and Ajax: From Novice to Professional, by Sas Jacobs. Another great web development book, showing how XML can be used effectively for web applications, including DOM scripting and Ajax (Apress, 2006).

• CSS Mastery, by Andy Budd, with Simon Collison and Cameron Moll. If you’re already familiar with CSS, then this book will take you up to the next level, with invaluable tech- niques and good practices (friends of ED, 2006).

• DOM Scripting:Web Design with JavaScript and the , by Jeremy Keith. This book will give you a good grounding in DOM scripting (friends of ED, 2005).

• Pro Ajax and Java: From Professional to Expert, by Nathaniel Schutta and Ryan Asleson. A great companion book to the one you’re reading now, this book also looks at the fusion of Java and Ajax, but from a more technology/workflow perspective rather than looking at complete projects. It covers setting up the perfect development environ- ment, testing and debugging, using Ajax libraries, and understanding the Ajax capabilities of Java frameworks such as Spring and JSF (Apress, 2006). Index

■A addPhoto() function, 293, 295 abort() method, 481 AddPhoto.java, for PhotoShare sample accessibility, 15 webapp, 303 account.js file, for The Organizer sample addPhoto.jsp file, for PhotoShare sample webapp, 339 webapp, 278 AccountAction.java, for The Organizer AddressBookManager class, 182–187 sample webapp, 346 addRoom() method, 404 accountCreate() method, 343 addRows() function, 170 accountCreate.jsp file, for The Organizer addToInventory() method, 460 sample webapp, 330 addUser() method, 385 accountCreateOK.jsp file, for The addUserToRoom() method, 389, 404 Organizer sample webapp, 330 Adobe, 483 AccountDAO.java, for The Organizer Ajax (Asynchronous JavaScript and XML) sample webapp, 343 alternatives to, 27–30 accountDelete() function, 339, 343 disadvantages of, 15 accountEdit.jsp file, for The Organizer pure, sample webapps and, 407–477 sample webapp, 332 URL for, 485 AccountObject.java, for The Organizer way of thinking and, 14 sample webapp, 341 tag, 118 accountRetrieve() method, 343 tag, 118 accountUpdate() function, 339, 343 tag, 206, 224 action mappings, AjaxChat and, 371 Ajax object, 316 Action.java, for PhotoShare sample tag, 206, 224 webapp, 301 AJAX Warrior sample application, 407–477 ActionContext object, 318, 346 approach to building, 408–413 ActionDispatcher.java, for PhotoShare client-side code for, 421–446 sample webapp, 297 displayed in action, 413 ActionForm, 357–359, 369 enhancing, exercises for, 476 DynaActionForm and, 371 maps/conversations and, 420 LobbyActionForm and, 384 sample Ajax function and, 409 Action class, WebWork and, 317, 346 server-side code for, 446–476 ActivityScroll.js file, for AJAX Warrior structure of, 417–421 sample webapp, 435 AjaxChat sample application, 353–406 Adaptive Path, 12 approach to building, 354–365 addCollection() method, 293, 300, 303 client-side code for, 370–383 AddCollection.java, for PhotoShare displayed in action, 365 sample webapp, 301 enhancing, exercises for, 406 addCollection.jsp file, for PhotoShare server-side code for, 383–405 sample webapp, 276 structure of, 367 addCollectionDigester() method, 300 AjaxChatConfig.java, for AjaxChat sample webapp, 383 489 490 ■INDEX

AjaxChatDAO.java, for AjaxChat sample appointmentEdit.jsp file, for The Organizer webapp, 394–405 sample webapp, 333 ajaxError() function, 337 appointmentList.jsp file, for The Organizer AjaxReader sample application, 203–253 sample webapp, 335 client-side code for, 212–231 AppointmentObject.java, for The Organizer displayed in action, 207 sample webapp, 341 exercises for, 253 appointmentRetrieve() function, 339 server-side code for, 231–253 appointments.js file, for The Organizer structure of, 211 sample webapp, 339 ajaxRef attribute, 118 arrayIndex property, 275 ajaxRequestSender() function, 121, 134 arrays, JavaScript and, 41 AjaxTags, 27, 115, 116–121 arrow keys, 129, 132 AjaxReader sample webapp and, 204 associative arrays, 256, 412 API documentation for, 116 assureUnique variable, 375 ajaxwarrior package, 446 assureUniqueGetMessages variable, 379 ajax_config. file, 118 AssureUniqueUsersInRoom variable, 379 for AjaxReader sample webapp, Asynchronous JavaScript and XML. See 215–217 Ajax for Karnak sample webapp, 135–137 Atom feeds, 204 alert() pop-ups, 16 ■ altRow variable, 169 B Amazing Karnak, 115 background-color style attribute, 80 anonymous functions, JavaScript and, 48 background style attribute, 80 Ant, 84–93, 483 backslash (\), JavaScript and, 45 ant-dependencies, 90 Banfield, Steve, 14 task, 90 basedir attribute, 89 Apache, 483 battleEnemyMove() function, 446 Apache Jakarta Commons, 483 BattleEnemyMoveCommand.java, for Apache Software Foundation AJAX Warrior sample webapp, 466 Ant. See Ant BattleFuncs.js file, for AJAX Warrior Digester, 107–111 sample webapp, 445 Geronimo, 97 battleMove() function, 445 Tomcat, 93, 485 BattleMoveCommand.endBattle() app-config.xml file, for AjaxChat sample method, 467 webapp, 372, 383 BattleMoveCommand.java, for AJAX AppConfigContextListener, 370 Warrior sample webapp, 464–466 appConfigured variable, 162 BEA’s WebLogic, 97, 483 appendChild() method, 66 tag, 373 applicationContext.xml file, for The beanPropertySetter rule, 295 Organizer sample webapp, 327 Berglund, Anders, 62 applications, 84–93, 96. See also sample Berners-Lee, Tim, 62 applications bindArgs variable, 256 applyElement() method, 66 tag, 22 AppointmentAction.java, for The Organizer booleans, JavaScript and, 46 sample webapp, 347–352 border style attribute, 80 AppointmentDAO.java, for The Organizer Bresenham line-drawing algorithm, 292 sample webapp, 343 ■INDEX 491 browsers, 14 client-side scripting, classic web cross-browser Ajax support and, 479 development and, 10 event handlers and, 130 ClientSideGameState.java, for AJAX XMLHttpRequest object and, 479 Warrior sample webapp, 456 buttonsAndTabs.js file, for The Organizer cloneNode() method, 66 sample webapp, 329, 336, 338 close() method, 200 ■ Collapse Sidebar button, 209, 226 C collapseExpandSidebar() function, 226, tag, 374 230 tag, 374, 378, 381 Collection.js file, for PhotoShare sample tag, 374 webapp, 281 tag, 374, 377 CollectionDTO.java, for PhotoShare calcLine() function, 292 sample webapp, 298 calculateDamage() method, 465 color style attribute, 80 callback handler function, 25 colors, CSS and, 76, 80 captureEvents() function, 130 comma-separated value (CSV), 62, 64 Find it faster at Carson, Johnny, 115 Command.java, for AJAX Warrior sample Cascading Style Sheets. See CSS webapp, 463 castSpell() function, 439 CommandResult.java, for AJAX Warrior CastSpell.js file, for AJAX Warrior sample sample webapp, 463 webapp, 439 commands package, 446 http://superindex.apress.com/ CastSpellCommand.java, for AJAX Warrior commands, for AJAX Warrior sample sample webapp, 467 webapp, 463–476 Caucho’s Resin, 97, 483 comments, JavaScript and, 40 Chain of Responsibility (CoR) Commons Digester, 68, 107, 243 implementation, 116 AjaxChat sample webapp and, 384 charPickLocation() method, 450, 452, 466 PhotoShare sample webapp and, 295, chat sample application. See AjaxChat 299 sample application Commons FileUpload component, 201 checkboxNumber variable, 162, 169 Commons Logging, 327, 385, 389 checkGameWon() method, 460, 470 commons-logging.properties file, for The checkName() function, 425 Organizer sample webapp, 327 class members, JavaScript and, 54 compareTo() method, 388 classes directory, 98 compile target, 88 clean target, 89 configClass context parameter, 370 clearAttributes() method, 66 configFile context parameter, 370 clearHistory() function, 382 ConfigInfo.java, for PhotoShare sample client-side code webapp, 296 for AJAX Warrior sample webapp, configuration files, XML and, 63 421–446 ContactAction.java, for The Organizer for AjaxChat sample webapp, 370–383 sample webapp, 347–352 for AjaxReader sample webapp, ContactDAO.java, for The Organizer 212–231 sample webapp, 343 for InstaMail sample webapp, 177–201 contactEdit.jsp file, for The Organizer for Karnak sample webapp, 125–134 sample webapp, 333 for PhotoShare webapp, 265–296 contactList.jsp file, for The Organizer for The Organizer sample webapp, sample webapp, 335 326–340 492 ■INDEX

ContactObject.java, for The Organizer custom handlers, 120 sample webapp, 341 CustomQueryString request handler, 130, contacts.js file, for The Organizer sample 136 webapp, 339 CustomQueryString.js, 124 context parameters, 100 for Karnak sample webapp, 126–134 contextInitialized() method, 296, 462 ■ ContextListener.java D for AJAX Warrior sample webapp, 462 Data Transfer Objects (DTOs), 357, for AjaxChat sample webapp, 369, 404 384–388 for The Organizer sample webapp, 340 data types, JavaScript and, 42–48 control.jsp file, for PhotoShare sample database engines, HSQLDB and, 319 webapp, 269–272 dayAtAGlance.jsp file, for The Organizer ControlEvents.js file, for PhotoShare sample webapp, 331 sample webapp, 293–296 DayAtAGlanceAction.java, for The Conversation.js file, for AJAX Warrior Organizer sample webapp, 347 sample webapp, 440 decreaseChatScrollFontSize() function, tag, 146 383 CoR (Chain of Responsibility) default attribute, 87 implementation, 116 Delete Feed button, 217 create() method, 346, 348 delete keyword, JavaScript and, 49 Create, Retrieve, Update, Delete (CRUD), delete() method, 346, 350 340, 343, 346 task, 88 createBattleMap() method, 454 deleteCollection() function, 294 createCharacter() method, 450, 466 DeleteCollection.java, for PhotoShare createDocument() function, 66 sample webapp, 304 createElement() method, 66 deleteContact() method, 175 createRolloverImages() function, 329, 336, DeleteFeedServlet, 249–253 338 deleteMessages() method, 172, 200 createTable() method, 341 deletePhoto() function, 294 createTextNode() method, 66 DeletePhoto.java, for PhotoShare sample CRUD (Create, Retrieve, Update, Delete), webapp, 306 340, 343, 346 deleteTempFiles() method, 311 CSS (Cascading Style Sheets), 72–82 dependency injection, 320 classic web development and, 10 depends attribute, 88 CSS Zen Garden, 78 description attribute, 88 CSS/CSS2, 77 development environment, 83 cssFeedHover selector, 231 died.jsp file, for AJAX Warrior sample cssInfoRowHeader, 269 webapp, 427 cssTextboxActive selector, 231 Digester, 107–111 CSV (comma-separated value), 62, 64 Direct Web Remoting (DWR), 144–147, 484 currentCollection variable, 293 DirectX filters, 276 currentSuggestion variable, 130 display style attribute, 80, 230 currentView variable, 162, 172, 336 displayInventory() function, 439 cursor attribute, 80, 231 displayInventory.jsp file, for AJAX Warrior for AjaxReader sample webapp, 230 sample webapp, 428, 468 for InstaMail sample webapp, 163 DisplayInventoryCommand.java, for AJAX for PhotoShare sample webapp, 272 Warrior sample webapp, 467 ■INDEX 493

tag, 23, 28 e-mail, webmail sample webapp and, CSS and, 74 143–201 selector styles and, 77 enableButtons() function, 164 Document Object Model. See DOM endBattle() method, 466 doDelete() function, 172 EndConversationCommand.java, for AJAX doesPlayerHaveSpell() function, 440 Warrior sample webapp, 468 doFilter() method, 462 Enter key, 131 doGet() method, 102, 140, 462 enterCommunity() function, 442 Dojo, 27, 254–258, 483 EnterCommunityCommand.java, for AJAX event handlers and, 257, 289 Warrior sample webapp, 468 Dojo packages, 255, 258 Enterprise JavaBeans (EJB), 17, 96 dojo.connect() function, 257 escape sequences, JavaScript and, 45 dojo.io package, 255 escape() function, 378, 382 dojo.io.bind() function, 255, 294 escapeXml() method, 390 DOM (Document Object Model), 22, eval() function, 226

56–61 event bubbling, 257 Find it faster at DOM manipulation methods, 66 event handlers, 119 DOM nodes, 56, 58 browsers and, 130 doMonthView() function, 340 custom, 120 doNewNote() function, 339 Dojo and, 257, 289

doPost() method, 102, 462 events, 117–120 http://superindex.apress.com/ doRedirect() method, 462 exec() method, 462 doRefreshHeadlines() function, 206, 229 BattleEnemyMoveCommand.java and, doScroller() function, 424 466 doWeekView() function, 340 Command.java and, 464 downloads EndConversationCommand.java and, Ant, 85 468 JDK, 83 SwitchWeaponCommand.java and, projects in this book, 111 472 Tomcat, 93 ToggleTalkAttackCommand.java and, doYearView() function, 340 474 drop shadows, 275 execute() method, 301, 318, 345 dsSelectorChange() function, 340 Expand Sidebar button, 226 DTOs (Data Transfer Objects), 357, Extensible Markup Language. See XML 384–388 ■ DWR (Direct Web Remoting), 144–147, 484 F dwr.xml file, InstaMail sample webapp fat clients, 5 and, 145–147 as alternative to Ajax, 30 DynaActionForm, 357–359, 369, 371, 394 FeedDescriptor DTO class, 231 feedForm, 224, 228 ■E feeds.properties file, 217, 236, 249 Eclipse, 84 filter package, 446 editContact() function, 165 tag, 101 EJB. See Enterprise JavaBeans filters, 100 elements, 117–120 finish() method, 462, 464 adding to web.xml file, 117 firstColumn variable, 428 Elipse, 484 Flash (Adobe), 483 as alternative to Ajax, 27 494 ■INDEX

Flex (Adobe), 483 GameTalkNode.java, for AJAX Warrior Flickr, 253 sample webapp, 461 float-overs, 157, 168 GameTalkReply.java, for AJAX Warrior PhotoShare sample webapp and, 272, sample webapp, 461 290 Garrett, Jesse James, 12, 485 font-family style attribute, 80 Generalized Markup Language (GML), 62 font-size style attribute, 80 Geronimo, 97, 483 font-style style attribute, 80 Getahead, 144 font-weight style attribute, 80 getAllResponseHeaders() method, 481 Form.serialize() function, 316 getAsString() method, 456

tag, 22 getAsXML() method, 298, 300 ForwardAction.java, for The Organizer getAttribute() function, 230 sample webapp, 345 getBaseMapChunk() method, 448 Fotki, 253 getBattleMap() method, 455 fraControl frame, 279 getBodyContent() method, 470 frames getCenterTile() method, 449 classic web development and, 10 getCheckbox() function, 169 hidden, 28 getChunk() method, 448, 469 framework package, 446 getCollection() method, 310 FreeMarker, 484 getCollectionList() method, 309 FrontServlet.java, for AJAX Warrior sample getConversation() method, 457 webapp, 462 getDescFromCode() method, 428, 447 fullTrim() function, 382 getElementById() method, 58 functions, JavaScript and, 36, 48 getElementsByTagName() function, 381 ■ getHeight() function, 290 G getInboxContents() method, 168, 196 game sample application. See AJAX getInstance() method, 299 Warrior sample application getItem() method, 452 GameCharacter.java, for AJAX Warrior getMessages() function, 379 sample webapp, 456 getMessages() method, 388, 404 GameConversation.java, for AJAX Warrior GetMessagesAction.java, for AjaxChat sample webapp, 457 sample webapp, 388 GameConversations.java, for AJAX Warrior getMessagesDelay variable, 379 sample webapp, 457 getMessagesHandler() function, 381 GameFuncs.js file, for AJAX Warrior getNoteObject() method, 350 sample webapp, 441–445 getPlayerTile() method, 469 GameItem.java, for AJAX Warrior sample getResponseHeader() method, 481 webapp, 457 getRoomList() method, 404 GameMaps.java, for AJAX Warrior sample getRoomsUserCounts() method, 389 webapp, 458 getRoomUserCounts() method, 404 GameMaps.loadMap() method, 462 getSentMessagesContents() method, 197 gameobjects package, 446 getSize() method, 304 gameState.getBattleCharacter() method, getUserList() method, 389, 404 467 getWidth() function, 290 GameState.java, for AJAX Warrior sample getXXXX functions, 163 webapp, 459–461 getXXXXObject() method, 348 GameState.js file, for AJAX Warrior sample webapp, 432 ■INDEX 495 global variables, 285, 336 HTML (Hypertext Markup Language) AJAX Warrior sample webapp and, 433 as alternative to Ajax, 28 Globals.java classic web development and, 10, 62 for AJAX Warrior sample webapp, 446 vs. CSS, 74 for The Organizer sample webapp, 340 tag, 363 Globals.js file tag, 373 for AJAX Warrior sample webapp, 429 tag, 376, 382 for PhotoShare sample webapp, 285 HttpServlet class, 102 globals.js file, for The Organizer sample Hypersonic SQL, 319 webapp, 336 Hypertext Markup Language. See HTML Gmail, 18 ■ GML (Generalized Markup Language), 62 I Goldfarb, Charles, 62 iBiblio, 90 Goodwin, Mark, 144 IBM’s WebSphere, 97, 484 IDE (integrated development Google, Ajax and, 19 environment), 84 Google Suggest, 13, 115 IDs, 58 Find it faster at gotoAddressBook() function, 174 if attribute, 90 gotoComposeMessage() function, 166 image preloads, 161, 227 gotoComposeReply() function, 166 PhotoShare sample webapp and, 271 gotoHelp() function, 166 The Organizer sample webapp and, gotoInbox() function, 166, 171 329, 336 http://superindex.apress.com/ gotoOptions() function, 175 ImageGrowing.js file, for PhotoShare gotoSentMessage() function, 171, 173 sample webapp, 292 gotoSentMessages() function, 172 increaseChatScrollFontSize() function, gotoViewMessage() function, 172 383 graphics, classic web development and, 10 index.htm file, for PhotoShare sample greeting.jsp file, for simple struts sample webapp, 266 application, 362 index.jsp file Gregory, Andrew, 479 for AJAX Warrior sample webapp, 422, growHeightStep variables, 292 462, 471 growImage() function, 292 for AjaxChat sample webapp, 373 growWidthStep variable, 292 for AjaxReader sample webapp, 217–230 ■H for InstaMail sample webapp, 153, hadChildNodes() method, 66 158–161 headerFile variable, 333 for Karnak sample webapp, 124 height style attribute, 80 for simple struts sample application, help.htm file, for AJAX Warrior sample 360 webapp, 428 for The Organizer sample webapp, 329 hidden frames, 28 index1.htm file, for PhotoShare sample hideAllLayers() function, 164 webapp, 267 hidePleaseWait() function, 165, 290 inEvent parameter, 228 hidePleaseWait() function, 290 info.jsp file, for PhotoShare sample highlighting changed information, 16 webapp, 268 Hotmail, 18 inheritance, JavaScript and, 53 HSQLDB, 319, 341, 484 init target, 87, 89 init() method, 102 496 ■INDEX

init.js file Java Web Parts (JWP), 116, 484 for AJAX Warrior sample webapp, 430 Java Web Parts project, 68 for The Organizer sample webapp, 336 JavaBeans, 17, 96 initConfigInfo() function, 296 task, 89 innerHTML property, 26 JavaScript, 34–56 insertBefore() method, 66 disadvantages of, 55 InstaMail sample application, 143–201 memory management and, 49 client-side code for, 153–177 object-oriented techniques and, 49–56 displayed in action, 147–152 parsing XML in, 64–72 enhancing, exercises for, 201 vs. Java, 34 HTTP servlet objects and, 187 JavaScript file, for Karnak sample webapp, server-side code for, 177–201 126–134 structure of, 152 JavaScript Object Notation (JSON), 407, instance members, JavaScript and, 54 411–413, 447 integrated development environment JavaServer Pages. See JSPs (IDE), 84 javax.servlet.jsp.jstl.fmt.localization- IntelliJ IDEA, 84, 484 Context parameter, 370 internationalization support, 370 JCL (Jakarta Commons Logging), 327, 385, IoC (Inversion of Control), 320 389 isAdd variable, 249 JDBC, 320 isCharacterNoWalkTile() method, 453 JdbcTemplate class, 320, 343 isItemSafeTile() method, 450, 453 JDK (J2SE Development Kit), 83 isItemTile() method, 453, 469 Tomcat and, 94 isNoWalkTile() method, 453 jEdit, 84, 484 isTileAlreadyOccupied() method, 454 Jetty, 96, 484 isUsernameInUse() method, 404 JoinRoomAction.java, for AjaxChat sample ■ webapp, 389 J JRE (Java Runtime Environment), 96 J2SE Development Kit (JDK), 83 JRun (Macromedia), 97, 484 Jakarta Commons JARs, 90 JSDigester, 68–72 Jakarta Commons Logging (JCL), 327, 385, PhotoShare sample webapp and, 295, 389 299 JAR files, 98 JSLib library, 67, 484 adding to webapps, 117 JSON (JavaScript Object Notation), 407, for AJAX Warrior sample webapp, 419 411–413, 447 for AjaxChat sample webapp, 369 JSP source files, for AJAX Warrior sample for AjaxReader sample webapp, 212 webapp (list), 419 for InstaMail sample webapp, 153 JSPs (JavaServer Pages), 17, 104 for Karnak sample webapp, 124 for Karnak sample webapp, 125 for PhotoShare sample webapp, 264 reasons for using/not using, 244 for The Organizer sample webapp, 325 rendering markup/XML and, 281 task, 89, 92 JSTL, 484 jarfile attribute, 89 JWP (Java Web Parts), 116, 484 Java, 83, 96 vs. JavaScript, 34 ■K parsing XML in, 107–111 Karnak sample application, 115–142 Java applets, as alternative to Ajax, 29 client-side code for, 125–134 Java Runtime Environment (JRE), 96 displayed in action, 121 ■INDEX 497

exercises for, 142 loadCollection.jsp file, for PhotoShare server-side code for, 134–142 sample webapp, 280 structure of, 123 loadHandler() function, 29 KarnakServlet class, 124 loadImage() function, 285 KarnetServlet.java file, 124, 137–142 loadMap() method, 458 keyCodePressed variable, 129, 142 loadPhotoImages() function, 283 keyDown() function, 130 lobby.jsp file, for AjaxChat sample KeyHandler.js file, for AJAX Warrior sample webapp, 374–378 webapp, 438 LobbyAction.java, for AjaxChat sample keyUp() function, 438 webapp, 389 keywords, JavaScript and, 38 LobbyActionForm.java, for AjaxChat ■ sample webapp, 384 L lobbyUpdateStatsDelay variable, 375 lastClickedLink variable, 227, 230 lobbyUpdateStatsHandler() function, 376 lastDateTime attribute, 388 locateDDValue() function, 336 layerCenterH() function, 423, 432 logging, The Organizer sample webapp Find it faster at layerCenterV() function, 432 and, 327 leaveRoom() method, 382 tag, 373 LeaveRoomAction.java, for AjaxChat LoginAction.java, for AjaxChat sample sample webapp, 389 webapp, 390–393 left style attribute, 80 logoff() function, 337 http://superindex.apress.com/ lib directory, 98 LogoffAction.java, for The Organizer libraries, 26, 483 sample webapp, 346 AjaxTags. See AjaxTags LogonAction.java, for The Organizer DWR, 144–147 sample webapp, 345 Prototype, 315 LogoutAction.java, for AjaxChat sample linkClicked() function, 230, 244 webapp, 393 list() method, 329, 348, 350 logUserId() method, 404 listAppointments() method, 344 logUserOut() method, 404 listCollections() function, 290 Lorie, Ray, 62 ListCollections.java, for PhotoShare sample Losher, Ed, 62 webapp, 308 listCollections.jsp file, for PhotoShare ■M sample webapp, 279, 290 task, 90 listener package, 446 Macromedia’s JRun, 97, 484 listeners, 100 MailDeleter class, 173, 197–201 ListFeedsServlet, 237 MailRetriever class, 191–197 ListHeadlinesServlet, 239–244 MailSender class 173, 188–191 listTasks() method, 344 main.jsp file ListUsersInRoomAction.java, for AjaxChat for AJAX Warrior sample webapp, 425 sample webapp, 389 for PhotoShare sample webapp, listUsersInRoomDelay variable, 379 272–276 listUsersInRoomHandler() function, 380 for simple struts sample application, literal values, JavaScript and, 41 360 loadCollection() function, 294 for The Organizer sample webapp, 330 LoadCollection.java, for PhotoShare mainContent ID, 331 sample webapp, 309 mainframes, 4 498 ■INDEX

Make, 85 notes.js file, for The Organizer sample make_jar target, 89 webapp, 339 manual event, 206, 217, 224 noteUpdate() function, 339 MapHandler.java, for AJAX Warrior sample null data type, JavaScript and, 46 webapp, 447–455 numbers, JavaScript and, 42 Mappr, 27 numSuggestions variable, 130, 141 margin attributes, 81 ■ Maven, 484 O Maven iBiblio repository, 90 object initializers, JavaScript and, 41 McMahon, Ed, 115 object-oriented JavaScript, 49–56 mergeAttributes() method, 66 Object-Relational Mapping (ORM), 320 tag, 64 objectCreate rule, 295 MessageDTO.java, for AjaxChat sample offsetHeight, 228 webapp, 384 oldUserListHTML variable, 379 method attribute, 318 onClick event handler, 226, 239 misc.js file The Organizer sample webapp and, for PhotoShare sample webapp, 331, 336 287–290 onLoad event handler, The Organizer for The Organizer sample webapp, 337 sample webapp and, 336 task, 88 onreadystatechange property, 25, 482 Model-View-Controller (MVC), 320 onSubmit handler, 225 mouse events Open In New Window button, 209, 226 AJAX Warrior sample webapp and, 425 open() method, 25, 481 AjaxReader sample webapp and, 239 OpenEJB, 96, 484 handlers for, 162 openInNewWindow() function, 226 PhotoShare sample webapp and, 257 OpenSymphony, 255, 317 The Organizer sample webapp and, openWindow() function, 267 331, 338 opResponse.jsp file, for The Organizer moveCharacters() method, 453, 476 sample webapp, 332 MVC (Model-View-Controller), 320 OptionsManager class, 145, 177–182

PhotoDTO.java, for PhotoShare sample ■R webapp, 298 readObject() method, 471 PhotoShare sample application, 253–312 readystate, 24, 482 client-side code for, 265–296 Really Simple Syndication (RSS), 203 displayed in action, 258 reconstitute() function, 432, 456 enhancing, exercises for, 312 Refresh Headlines button, 226, 228 server-side code for, 296–312 removeAllRows() function, 168 structure of, 262 removeCharacter() method, 450, 466 PhotoShareDAO.java, for PhotoShare removefromInventory() method, 460 sample webapp, 299 removeInactiveUsers() method, 394, 404 pickUpItem() function, 409–411, 442 removeItem() method, 453, 470 PickUpItemCommand.java, for AJAX removeNode() method, 67 Warrior sample webapp, 469 removeRoom() method, 404 PIM (personal information manager) removeUser() method, 404 sample application, 313–352 removeUserFromAllRooms() method, 404 placeCharacter() method, 448 removeUserFromRoom() method, 389, Find it faster at placeCharacters() method, 450 404 placeItems() method, 448 repeat() method, 455 Please Wait float-over, 157, 164, 168 replaceNode() method, 67 PhotoShare sample webapp and, 272, replyGetInboxContents() function, 166,

290 168 http://superindex.apress.com/ pleaseWait ID, 331 request attributes, 105 PleaseWait.js file, for PhotoShare sample request handlers, 119 webapp, 290 Request() function, 316, 339 polymorphism, 49 reserved words, JavaScript and, 38 POP3, 143 resetLandingPad() function, 290 port 8080, 147 resetScroller() function, 423 position style attribute, 81 resetVars() function, 290 postedDateTime, 388 Resin (Caucho), 97, 483 postMessage() function, 382, 387, 404 resources for further reading, 483–487 PostMessageAction.java, for AjaxChat Bresenham line-drawing algorithm, 292 sample webapp, 394 CSS, 78 previousSuggestion variable, 129 DirectX filters, 276 Prototype, 27, 315, 339 DOM scripting, 59 $() function and, 336 JSON, 413 website for, 484 Spring, 321 proxyHost parameter, 214, 243 W3C Schools, 82 proxyPort parameter, 214, 243 response handlers, 119 purchaseItem() function, 436 responseText property, 482 PurchaseItemCommand.java, for AJAX responseXML property, 482 Warrior, 470 retrieve() method, 346, 348 push() method, 435 retrieveContact() method, 187 queryForList() method, 343 retrieveMessage() function, 197 ■Q retrieveMethod() method, 172 retrieveOptions() method, 176, 181 QueryString request handler, 130 Return key, 131 500 ■INDEX

RIAs (Rich Internet Applications), 17, 27 saveOptions() function, 176, 182 rollover effects SAX (Simple API for XML), 67, 109 AjaxReader sample webapp and, 225, sax.js file, 67 227 scope, JavaScript and, 36 The Organizer sample webapp and,