introduction to introduction to dojo toolkit dojo toolkit

26
1 Introduction to Introduction to Dojo Toolkit Dojo Toolkit 1

Upload: sampetruda

Post on 26-Jan-2015

2.775 views

Category:

Documents


10 download

DESCRIPTION

 

TRANSCRIPT

Page 1: Introduction to Introduction to Dojo Toolkit Dojo Toolkit

1

Introduction to Introduction to Dojo ToolkitDojo Toolkit

1

Page 2: Introduction to Introduction to Dojo Toolkit Dojo Toolkit

2

Topics• What is and Why Dojo Toolkit?• Dojo Architecture • Loading Dojo toolkit• Remoting (Ajax operation)• Dojo Helloworld example

Page 3: Introduction to Introduction to Dojo Toolkit Dojo Toolkit

3

Topics Covered in Advanced DojoPresentation• Creation of Dojo Widgets• Dojo Drag and Drop• Dojo Animation• Dojo Storage• Performance tuning

Page 4: Introduction to Introduction to Dojo Toolkit Dojo Toolkit

What is andWhat is andWhy Dojo Toolkit?Why Dojo Toolkit?

Page 5: Introduction to Introduction to Dojo Toolkit Dojo Toolkit

5

What is Dojo Toolkit?• Open Source DHTML toolkit written in JavaScript

> It is a set of JavaScript libraries• Aims to solve some long-standing historical

problems with DHTML> Browser incompatibility

• Allows you to easily build dynamic capabilities into web pages> Widgets> Animations

• Server technology agnosticsource: dojotoolkit.org

Page 6: Introduction to Introduction to Dojo Toolkit Dojo Toolkit

6

Why Dojo Toolkit?

• You can use Dojo to make your web applications more useable, responsive, and functional> Supports AJAX

• Dojo provides lots of plumbing facilities> Hides XMLHttpRequest processing> Handles browser incompatibilities

• Strong developer community

source: dojotoolkit.org

Page 7: Introduction to Introduction to Dojo Toolkit Dojo Toolkit

7

Features of Dojo Toolkit• Powerful AJAX-based I/O abstraction (remoting)• Graceful degradation• Backward, forward, bookmarking support• Aspect-oriented event system• Markup-based UI construction through widgets• Widget prototyping• Animation• Lots of useful libraries

Page 8: Introduction to Introduction to Dojo Toolkit Dojo Toolkit

Dojo ArchitectureDojo Architecture

Page 9: Introduction to Introduction to Dojo Toolkit Dojo Toolkit

9

Dojo Toolkit Libraries

Page 10: Introduction to Introduction to Dojo Toolkit Dojo Toolkit

10

Dojo Toolkit: 3 main parts: Dojo

> Browser normalization, package loading, DOM access and manipulation, Firebug Lite debugging, events, data access, Drag and drop, Asynchronous remote calls, JSON encoding/decoding

dijit > Interface widgets, Advanced UI controls,Template driven

dojoX> Inventive innovative: graphics, offline, widgets like grid

spreadsheat,

Page 11: Introduction to Introduction to Dojo Toolkit Dojo Toolkit

Loading Dojo Toolkit Loading Dojo Toolkit

Page 12: Introduction to Introduction to Dojo Toolkit Dojo Toolkit

12

Two Options

• Load it from the network• Load it from locally installed version

Page 13: Introduction to Introduction to Dojo Toolkit Dojo Toolkit

13

(Option 1) Load it from network

• Download nothing and simply pull Dojo from the networkAOL: <SCRIPT TYPE="text/javascript" SRC="http://o.aolcdn.com/dojo/1.2.0/dojo/dojo.xd.js"></SCRIPT>

Google: <SCRIPT TYPE="text/javascript" SRC=”http://ajax.googleapis.com/ajax/libs/dojo/1.2.0/dojo/dojo.xd.js"></SCRIPT>

script element is responsible for loading the base Dojo script

Page 14: Introduction to Introduction to Dojo Toolkit Dojo Toolkit

14

(Option 2) Load it from locally installed version

• Download from http://dojotoolkit.org/downloads <script type="text/javascript" djConfig="parseOnLoad: true" src="js/dojo/dojo.js" > </script>

script element is responsible for loading the base Dojo script

The package system handles the loading of all other dependencies and modules once dojo.js has been loaded into the page

Page 15: Introduction to Introduction to Dojo Toolkit Dojo Toolkit

15

Setting up dojo javascript in the page

<head> <style type="text/css"> @import "js/dojo/resources/dojo.css";"; </style> <script type="text/javascript" src="js/dojo/dojo.js" djConfig="parseOnLoad: true" isDebug: true > </script></head>

Use firebug lite for debugging

Load the dojo style sheet

Page 16: Introduction to Introduction to Dojo Toolkit Dojo Toolkit

RemotingRemoting(Ajax operations)(Ajax operations)

Page 17: Introduction to Introduction to Dojo Toolkit Dojo Toolkit

17

Traditional Web AJAX within a browser, there is AJAX engine

Page 18: Introduction to Introduction to Dojo Toolkit Dojo Toolkit

18

Performing XMLHttpRequest (XHR)

• dojo.xhrGet()• dojo.xhrPost()• dojo.xhrDelete()• dojo.xhrPut()

Page 19: Introduction to Introduction to Dojo Toolkit Dojo Toolkit

19

dojo.xhrGet()

• The dojo.io.* namespace contains generic APIs for doing network I/O> dojo.xhrXXX() hides low-level XMLHttpRequest operations

• Also handles> back-button interception> transparent form submission> advanced error handling

Page 20: Introduction to Introduction to Dojo Toolkit Dojo Toolkit

20

Getting Data from the Server <script type="text/javascript"> dojo.xhrGet({ url: 'sayHello', load: helloCallback, error: helloError, content: {name: dojo.byId('name').value } });

</script>

call url

Callback function

Content to send

On error function

Page 21: Introduction to Introduction to Dojo Toolkit Dojo Toolkit

Example: DojoExample: DojoHelloWorld ExampleHelloWorld Example

Page 22: Introduction to Introduction to Dojo Toolkit Dojo Toolkit

22

Connecting an Event to the Widget

<head>... <script type="text/javascript"> dojo.require("dijit.form.Button"); </script>...</head><body class="tundra">

Name: <input name="Name" id="name" type="text" />

<button dojoType="dijit.form.Button" id="helloButton"> Hello World! <script type="dojo/method" event="onClick"> makeAjaxCall(); </script></button>

</body> attach an event to button through a script type of dojo/method

Page 23: Introduction to Introduction to Dojo Toolkit Dojo Toolkit

23

Getting Data from the Server<head> <script type="text/javascript"> function makeAjaxCall(){ dojo.xhrGet({ url: 'sayHello.jsp', load: helloCallback, error: helloError, content: {name: dojo.byId('name').value } }); } function helloCallback(data,ioArgs) { dojo.byId("returnMsg").innerHTML = data; } </script></head><body> Name: <input name="Name" id="name" type="text" /> <button dojoType="dijit.form.Button" <script type="dojo/method" event="onClick"> makeAjaxCall(); ... <p id=returnMsg></p>

Page 24: Introduction to Introduction to Dojo Toolkit Dojo Toolkit

24

The sayHello JSP

<% String returnString = request.getParameter("name");

if (returnString == null || returnString.isEmpty()) { // Return error message returnString = "Name is required."; out.print("Error: " + returnString); } else { // Return the name out.print("Hello: " + returnString); }%>

Page 25: Introduction to Introduction to Dojo Toolkit Dojo Toolkit

25

dojo.xhrPost a Form <head> <script type="text/javascript"> function makeAjaxCall(){ dojo.xhrPost({ url: 'sayHello', load: helloCallback, error: helloError, form: 'myForm' }); } function helloCallback(data,ioArgs) { dojo.byId("returnMsg").innerHTML = data; } </script></head><body> <form id="myForm" method="POST"> Name: <input type="text" name="name"> </form> <button dojoType="dijit.form.Button" <script type="dojo/method" event="onClick"> makeAjaxCall();

<p id=returnMsg></p></body>

Page 26: Introduction to Introduction to Dojo Toolkit Dojo Toolkit

26

Introduction to Introduction to Dojo ToolkitDojo Toolkit

26