Ajax on Java

Book description

This practical guide shows you how to make your Java web applications more responsive and dynamic by incorporating new Ajaxian features, including suggestion lists, drag-and-drop, and more. Java developers can choose between many different ways of incorporating Ajax, from building JavaScript into your applications "by hand" to using the new Google Web Toolkit (GWT).

Ajax on Java starts with an introduction to Ajax, showing you how to write some basic applications that use client-side JavaScript to request information from a Java servlet and display it without doing a full page reload. It also presents several strategies for communicating between the client and the server, including sending raw data, and using XML or JSON (JavaScript Object Notation) for sending more complex collections of data.

The book then branches out into different approaches for incorporating Ajax, which include:

  • The Prototype and script.aculo.us Javascript libraries, the Dojo and Rico libraries, and DWR
  • Integrating Ajax into Java ServerPages (JSP) applications
  • Using Ajax with Struts
  • Integrating Ajax into Java ServerFaces (JSF) applications
  • Using Google's GWT, which offers a pure Java approach to developing web applications: your client-side components are written in Java, and compiled into HTML and JavaScript

Ajax gives web developers the ability to build applications that are more interactive, more dynamic, more exciting and enjoyable for your users. If you're a Java developer and haven't tried Ajax, but would like to get started, this book is essential. Your users will be grateful.

Publisher resources

View/Submit Errata

Table of contents

  1. Ajax on Java
  2. Dedication
  3. A Note Regarding Supplemental Files
  4. Preface
    1. Ajax: Some History
    2. Audience
    3. Assumptions This Book Makes
    4. Contents of This Book
    5. Conventions Used in This Book
    6. Using Code Examples
    7. How to Contact Us
    8. Safari® Books Online
    9. Acknowledgments
  5. 1. Setup
    1. 1.1. Requirements
    2. 1.2. Installing Tomcat
      1. 1.2.1. A Minimalist Guide to Setting Up Tomcat
      2. 1.2.2. Setting TOMCAT_HOME
    3. 1.3. Installing Ant
  6. 2. JavaScript for Ajax
    1. 2.1. Creating the Application
      1. 2.1.1. How Is Our JavaScript Function Called?
      2. 2.1.2. How Do We Get the Value of the Key Pressed?
      3. 2.1.3. Formatting the Page
    2. 2.2. Running the Example
  7. 3. A Simple Ajax Servlet
    1. 3.1. Building and Deploying the Ajax Application
      1. 3.1.1. Directory Structure
    2. 3.2. Running the Example
      1. 3.2.1. So Where’s the XML?
  8. 4. XML and JSON for Ajax
    1. 4.1. The Character Decoder
    2. 4.2. Setting Up a Simple XML Document
      1. 4.2.1. Using a Servlet to Build an XML Document
      2. 4.2.2. Other Ways to Build the XML Document
        1. 4.2.2.1. JDOM
        2. 4.2.2.2. dom4j
        3. 4.2.2.3. SAX
    3. 4.3. Back on the Client: Mining the XML
      1. 4.3.1. XML Parsing with JavaScript
      2. 4.3.2. Populating the Form on a Microsoft Browser
      3. 4.3.3. Populating the Form on Other Browsers
    4. 4.4. Building the Application
    5. 4.5. Running the Application on Tomcat
    6. 4.6. Passing Data with JSON
      1. 4.6.1. Changing the JavaScript for JSON
    7. 4.7. Summary
  9. 5. Getting Useful Data
    1. 5.1. Form Entry with Ajax
      1. 5.1.1. Validating the Username
      2. 5.1.2. Creating the Database
      3. 5.1.3. Servicing the Ajax Request: Servlets
      4. 5.1.4. Loading City and State by Zip Code
    2. 5.2. Building a Suggestion Field
      1. 5.2.1. Retrieving the Usernames
      2. 5.2.2. Creating the Div
      3. 5.2.3. Handling the Events
        1. 5.2.3.1. Highlighting a suggestion
      4. 5.2.4. Configuring the Servlets
  10. 6. Ajax Libraries and Toolkits
    1. 6.1. Using the Dojo Toolkit
    2. 6.2. Using the Rico Toolkit
      1. 6.2.1. Using Rico’s Object Response Type
    3. 6.3. Using DWR with Ajax
    4. 6.4. Drag ‘n’ Drop with Scriptaculous and Prototype
      1. 6.4.1. The User Signup Application
      2. 6.4.2. Using Prototype to Wrap XMLHttpRequest
      3. 6.4.3. The User Login Functions
      4. 6.4.4. The Shopping Functions: Getting a Product List
  11. 7. Ajax Tags
    1. 7.1. Creating a Tag Library
      1. 7.1.1. Writing a TLD
      2. 7.1.2. Using the Tags in a JSP
      3. 7.1.3. Writing the TagSupport Class
      4. 7.1.4. Writing the Support Servlet
      5. 7.1.5. Using Ant to Put It All Together
    2. 7.2. Third-Party Tag Libraries
      1. 7.2.1. AjaxTags
        1. 7.2.1.1. Getting and installing AjaxTags
        2. 7.2.1.2. Using the <tabPanel> tag
        3. 7.2.1.3. Writing the servlet code
        4. 7.2.1.4. Displaying data in the tabs
      2. 7.2.2. JavaWebParts
      3. 7.2.3. AjaxAnywhere
        1. 7.2.3.1. Enabling AjaxAnywhere in the JSP
        2. 7.2.3.2. Refresh zones
        3. 7.2.3.3. Writing support for AjaxAnywhere
        4. 7.2.3.4. The AjaxAnywhere filter
      4. 7.2.4. Which Tag Library Should I Use?
  12. 8. Ajax on Struts
    1. 8.1. Struts-Layout
      1. 8.1.1. Installing Struts-Layout
      2. 8.1.2. Writing the Struts-Layout JSP
      3. 8.1.3. Struts Action Forms
      4. 8.1.4. What’s an Action, and What Happened to My Servlet?
      5. 8.1.5. The Struts Configuration
      6. 8.1.6. Where Does the Data Come From?
      7. 8.1.7. Populating the Suggestion List
      8. 8.1.8. Struts-Layout Is Cool Because...
    2. 8.2. Adding Ajax to Struts with DWR
      1. 8.2.1. Uploading Files
      2. 8.2.2. Creating the JSP
      3. 8.2.3. Writing the DWR Configuration File
      4. 8.2.4. Displaying the Products in the Browser
      5. 8.2.5. Viewing the DWR-Generated JavaScript
      6. 8.2.6. Writing the ProductManager Class
      7. 8.2.7. DWR Is Cool Because...
    3. 8.3. Ajax with Struts: What Have We Learned Here?
  13. 9. JavaServer Faces and Ajax
    1. 9.1. The JSF Lifecycle
    2. 9.2. Writing a Custom JSF Component
      1. 9.2.1. Writing the JSP Page for the JSF Application
      2. 9.2.2. Configuring JSF: web.xml and faces-config.xml
    3. 9.3. Developing a Custom JSF Tag
      1. 9.3.1. Writing the TLD File
      2. 9.3.2. Writing the Tag Handler
      3. 9.3.3. Creating a Renderer and Render Kits
      4. 9.3.4. Writing the JavaScript Support File
    4. 9.4. Handling JSF Input by Extending HtmlInputText
    5. 9.5. Writing the JSF Support for Ajax
    6. 9.6. Summary
  14. 10. Google Web Toolkit
    1. 10.1. Getting Started with GWT
      1. 10.1.1. Hosted Mode Versus Web Mode
    2. 10.2. Debugging the Application
    3. 10.3. Fleshing Out the Application: The Client
      1. 10.3.1. Customizing the Client
    4. 10.4. Supplying Services to the Client
      1. 10.4.1. Connecting the Client to the Service
      2. 10.4.2. Connecting the Service to the Servlet URL
    5. 10.5. Testing ZipCodes with the Service
    6. 10.6. GWT Widgets
  15. Index
  16. About the Author
  17. Colophon
  18. Copyright

Product information

  • Title: Ajax on Java
  • Author(s): Steven Douglas Olson
  • Release date: February 2007
  • Publisher(s): O'Reilly Media, Inc.
  • ISBN: 9780596553647