Benefits of Dojo

This page discusses - Benefits of Dojo

Benefits of Dojo

Benefits of Dojo

       

Benefits of Dojo

Following are the benefits of Dojo.

  • Associative arrays
  • Loosely typed variables
  • Regular expressions
  • Objects and classes
  • Highly evolved date, math, and string libraries
  • W3C DOM support in the Dojo

Disadvantages of Dojo Following are the Disadvantages of Dojo.

  • Developer depends on the browser support for the Dojo
  • There is no way to hide the Dojo code in case of commercial application
  • Directory Structure: fallow the directory structure with Tomcat server for dojo programming

Learn the basics of Dojo and create your first Dojo program.

In this tutorial, you will learn how to create a "Hello World" example in Dojo. Before creating any examples or applications you must be follow the its directory structure .

The following example we are going to create a button "Hello World!". To create a button in dojo you need to a Button Widget that contains three visual states as: mouseOut, mouseOver and mouseDown. To follow the following steps for creating a dojo button widget:

 

<script type="text/javascript">
  // Load Dojo's code relating to widget managing functions
  dojo.require("dojo.widget.*");

  // Load Dojo's code relating to the Button widget
  dojo.require("dojo.widget.Button");
</script>

dojo.require("dojo.widget.*"): It instructs you to include the dojo widget (Not load all the widgets) for managing functions. 

dojo.require("dojo.widget.Button"): This line instructs you to load the Dojo button widget. If you don't include this line, the markup code for the button would not be evaluated by Dojo upon loading, resulting in a plain HTML button instead of what you expect.

Insert the following code into the  HTML body:

<button dojoType="Button" widgetId="helloButton" 

onClick="helloPressed();">Hello World!</button>

The key attribute of this HTML element to notice is the dojoType attribute. This is responsible for instructing Dojo on how to process the element when the page is loading. In this case you will use a button element for the button that is used to input element - Dojo will work with either as long as the dojoType attribute is present .

widgetId="helloButton" :  This is replaced with id="helloButton" without the functionality being affected - Dojo's widget system is smart enough to convert regular id attributes to widgetId's if no widgetId` attribute is explicitly named .

Connecting an Event to the Widget

When you click the command button then it doing something? We specify an onClick event handler for the given command button.

dojo.require("dojo.event.*");

Above code we use "dojo.event.*" that includes all events functionality of Dojo (But not all widgets). 

Following function that will called by the button when we clicked. After clicking the "helloPressed" method is called and it displays an alert message like: "Click on the Hello World Button". 

function helloPressed()
{
alert('Click on the Hello World Button');
}

Here is the code of program:

By this code and above description, you will learn how to create a "Hello World" example in Dojo. Before creating any examples or applications you must be follow the its directory structure.

<html>

<head>
<title>button</title>
   <script type= "text/javascript" >
   dojo.require( "dojo.event.*" );
   dojo.require( "dojo.widget.*" );
   dojo.require( "dojo.widget.Button" );

   function helloPressed()
   {
   alert( 'Cl ick on the Hello World Button ');
   }

   function init()
   {
   var helloButton = dojo.widget.byId( 'he lloButton ');
   dojo.event.connect(helloButton,  'on Click ', 'he lloPressed ')
   }

   dojo.addOnLoad(init);
   </script>


</head>

<body bgcolor= "#FFFFCC" >

<p align= "center" ><font size= "6"  color= "#800000" >Welcome to Roseindia Dojo Project</font></p>

<button dojoType= "Button"  widgetId= "helloButton"  onClick= "helloPressed();" >Hello World!</button>
<br>
  
</body>

</html>