Newsletter sign-up
View all newsletters

Enterprise Java Newsletter
Stay up to date on the latest tutorials and Java community news posted on JavaWorld

Sponsored Links

Optimize with a SATA RAID Storage Solution
Range of capacities as low as $1250 per TB. Ideal if you currently rely on servers/disks/JBODs

Introduction to the Dojo toolkit, Part 1: Setup, core, and widgets

Object-oriented JavaScript programming for Java developers

  • Print
  • Feedback

Page 2 of 6

Installing the Dojo toolkit

The Dojo toolkit depends on set of JavaScript, CSS, and HTML files to be available in a predefined directory structure at runtime. You can install Dojo in one of three ways:

  1. Use Dojo from a content-delivery network (CDN): The easiest way to install Dojo is to use an instance that is available on a CDN near you. For example, you can install the 1.2 version of Dojo by including one of two script tags on your page:
    • Points to AOL's CDN:

      <SCRIPT TYPE="text/JavaScript" SRC="http://o.aolcdn.com/dojo/1.2/dojo/dojo.xd.js"/>
      
    • Points to Google's CDN:

      <SCRIPT TYPE="text/JavaScript"> SRC="http://ajax.googleapis.com/ajax/libs/dojo/1.2/dojo/dojo.xd.js"/>
      
  2. Install Dojo on your server: First, download the latest Dojo release. Once you have the release .zip file, you can unzip it on your Web server so that all your Web applications can use it. Or, if prefer to have a separate version of Dojo for each of your Web applications, then you can unzip the Dojo .zip files in one of the WebContent subdirectories, such as the js folder, of your Java EE Web application. Now you can use Dojo by including this script tag in your Web page:

    <SCRIPT TYPE="text/JavaScript" SRC="js/dojo/dojo.js"/>
    

    When you download the Dojo binaries, you can get either the source or release version. You should always use the release version in your production environment because it is compressed and optimized for faster download. You can use the source version in your development environment if you want to debug Dojo to learn how it works under the hood.
  3. Install the latest development build on your server: Download the nightly Dojo release, then follow the post-download steps in option 2 above. Note that this approach is only for advanced users, and you should have a compelling reason to choose it.

The Dojo framework code is split into multiple files, but once dojo.js is loaded it will automatically download all necessary remaining files. You can verify that Dojo is installed correctly by accessing <BASEURL>/js/dijit/themes/themeTester.html. This URL opens an HTML page displaying various Dijit widgets.

Setting up your debug environment

Firebug is an open source debugging extension for Firefox. It provides tools for debugging JavaScript, CSS, and HTML. Firebug Lite lets you simulate Firebug functionality in other browsers such as Internet Explorer, Opera, and Safari.

Firebug does the following:

  • Allows you to debug and profile JavaScript.
  • Provides a log4j-like JavaScript logging framework.
  • Monitors the time that it takes to download resources such as .js, .css, and image files. It can be used to monitor XMLHttpRequests and responses.
  • Lets you inspect and edit the live HTML generated by JavaScript.
  • Displays all the CSS styles on the page and allows you to try out your changes online without a page refresh.

I strongly recommended that you use Firefox wtih Firebug during the development phase. Dojo takes care of cross-browser compatibility issues, so code that works in Firefox should also work in other browsers.

  • Print
  • Feedback

Resources

More from JavaWorld