Introduction to DOJO Toolkit

Introduction

– Dojo is an Open Source DHTML toolkit / Dojo is JavaScript framework released as open source software. – Dojo delivers on the promise of Web 2.0 terms like Comet and Ajax by helping you create rich and interactive web apps. – It builds on several contributed code bases like widgets. It is unified toolkit. – Dojo provides higher abstraction layer to the programmer. So, it helps the programmers to develop powerful functions very easily. – Dojo offers many widgets, utilities and Ajax libraries to develop your application. It’s a great framework for developing Ajax based applications.

Why DOJO?

– It helps in DOM scripting. – It helps in event management. – It shortens the time between idea and implementation by providing a well conceived API and set of tools for assisting and fixing the issues experienced in everyday web development – It provides an abstraction over the difficult JavaScript. – We can use arrays, object, classes , and many more inbuilt components as easily as we include a <input> tag in the HTML pages.

Downloading DOJO

Download the newest released version of the Dojo Toolkit from: http://dojotoolkit.org/download/ Unpack the contents of the archive into a folder. You will see the following folders. You can get a dojoroot folder and three other folders dijit, Dojo, dojox. You just have to place these folders into your WebContent folder of J2EE project.

Folder Structure

Dijit – Dijit makes a developing and reusing interface components very easy. If you can write HTML and CSS, Dijit allows you to quickly build reusable client side components. It contains js files for reusable components as well as demos. DOJOX – “Edge of the web” features are being developed in the Dojox namespace. It provides a sandbox where these new components can be added without constrained by the high standard of testing. Individual projects in the dojox contains README file. DOJOX – Dojo features built-in internationalization and localization support, full accessibility hinting in all Dijit widgets. Infrastructure to support keyboard event handling and the ability to theme all Dijit components using only CSS. For using any of the components in Dojo toolkit you have to have knowledge of above all folders. You can get all the demos and code for creating a rich UI.

DOJO component

Dojo framework comes up with many components like – DOJO Tree – DOJO filtering Select – DOJO combo box – DOJO Button – DOJO Calendar control – DOJO Grid

Coding in DOJO

To use dojo we have to write some script and include some style sheets which have the default styles to the component.
<style type="text/css"> @import "dojoroot/dijit/themes/tundra/tundra.css"; @import "dojoroot/dojo/resources/dojo.css"; </style> <script type="text/javascript" src="dojoroot/dojo/dojo.js" djConfig="parseOnLoad: true"> </script> <script type="text/javascript"> dojo.require("dojo.data.ItemFileWriteStore"); dojo.require("dojo.data.ItemFileReadStore"); dojo.require("dijit._tree.dndSource"); dojo.require("dijit.Tree"); dojo.require("dojo.parser"); dojo.require("dojo.dnd.Source"); </script>
Code language: HTML, XML (xml)
This line i.e “dojo.require“ instruct you to load the Dijit tree widget. If you don’t include this line, the markup code for the tree would not be evaluated by Dojo upon loading. You always have to include particular component you are using in your application. JSP File
<body class="tundra"> <h1>Tree Drag And Drop</h1> <div dojoType="dojo.data.ItemFileReadStore" url="TreeData" jsid="popStore"> </div> <div dojoType="dojo.data.ItemFileWriteStore" url="newtree.json" jsid="newtree" /> </div> <table> <tr> <td> <div dojoType="dijit.Tree" store="popStore" labelAttr="Tree" checkAcceptance="stopDnd" dndController="dijit._tree.dndSource" label=“Root" jsid="ptTree"> <script type="dojo/method" event="getLabelClass" args="item"></script> </div> </td> <td> <div dojoType="dijit.Tree" jsid="newTree" label="Drop Selection Here" class="source" store="newtree" onClick="onClick" labelAttr="name" childrenAttr="children, items" onDndDrop="tree2CustomDrop" dndController="dijit._tree.dndSource" checkAcceptance="dndAccept"> </div> </td> </tr> </table> <br> <br> <div id="selection"></div> ... ...
Code language: HTML, XML (xml)
<div dojoType="dojo.data.ItemFileWriteStore" url="newtree.json" jsid="newtree" /> This line reads the tree parents n child nodes from a json “newtree.json”. For reading that store we have to use “ItemFileWriteStore” which is of dojotype. <div dojoType="dijit.Tree" jsid="newTree" label="Drop Selection Here" class="source" store="newtree" onClick="onClick" labelAttr="name" childrenAttr="children, items" In above line we assign a dojo type to the formed jsid. And provide a method onclick for writing a required behavior of tree.
Code language: HTML, XML (xml)
Lastly we have to make an entry of servlet in StrutsConfig.xml We can form a json string in the servlet only and pass it to the client. I.e. front end. Making Ajax call from a js using DOJO is somewhat different.
var dataUrl = "FetchTreeCriteria.do"; var xhrArgs = {url: dataUrl+"?"+"cell_Id="+cellId,handleAs: "json-comment-optional", preventCache: true}; var gotData = function(data){ //Fetching a data from database. } var rdata = dojo.xhrGet(xhrArgs); rdata.addCallback(gotData);
Code language: JavaScript (javascript)
By using an above code you can make Ajax call and by providing a variable after question mark we can pass request parameters to the Servlet. By using xhrGet method we can make XHR call. All Dojo XHR methods are bi-directional. The only difference is the method. Using dojo.xhrPost, we use the POST method, embedding the data in the request (as opposed to the query string as with dojo.xhrGet). The data can be set directly as an object passed to the content: parameter.

View Comments

Share
Published by
Charuta Chaudhri
Tags: Dojo dojo framework Dojo toolkit JavaScript javascript framework

Recent Posts

  • Java

Java URL Encoder/Decoder Example

Java URL Encoder/Decoder Example - In this tutorial we will see how to URL encode/decode…

5 years ago
  • General

How to Show Multiple Examples in OpenAPI Spec

Show Multiple Examples in OpenAPI - OpenAPI (aka Swagger) Specifications has become a defecto standard…

5 years ago
  • General

How to Run Local WordPress using Docker

Local WordPress using Docker - Running a local WordPress development environment is crucial for testing…

5 years ago
  • Java

Create and Validate JWT Token in Java using JJWT

1. JWT Token Overview JSON Web Token (JWT) is an open standard defines a compact…

5 years ago
  • Spring Boot

Spring Boot GraphQL Subscription Realtime API

GraphQL Subscription provides a great way of building real-time API. In this tutorial we will…

5 years ago
  • Spring Boot

Spring Boot DynamoDB Integration Test using Testcontainers

1. Overview Spring Boot Webflux DynamoDB Integration tests - In this tutorial we will see…

5 years ago