Академический Документы
Профессиональный Документы
Культура Документы
0 Related
Frameworks and toolkits
Tao Michael Li
Technology Evangelist
Sun Microsystems, Inc.
11
Agenda
• AJAX Basics
> AJAX Interaction:Using Sample Application
• AJAX Toolkits and Frameworks
> Dojo Client-side JavaScript Library
> jMaki
> AJAX-enabled JavaServer Faces
> Wicket
> Google Web Toolkit
> Direct Web Remoting
AJAX Basics:
What is AJAX?
What is AJAX?
• AJAX= acronym for:
> Asynchronous JavaScript and XML
• Browser client uses JavaScript to Asynchronously
get XML data from a server and update page
dynamically without refreshing the whole page
User Interface: Traditional Web vs.
AJAX User operation
01100110
01111001
01101011
stops while
Stateless
Synchronous call
the data is being
HTML View Stateful
Server fetched
Browser
New HTML page
011001101101
111110010100
011010111101
110011010110
<input type="text"
size="20"
id="userid"
name="id"
onkeyup="validateUserId();">
Anatomy of an AJAX Interaction
Data Validation Example
2. An XMLHttpRequest object is created
var req;
function initRequest() {
if (window.XMLHttpRequest) {
req = new XMLHttpRequest(); XMLHttpRequest
} else if (window.ActiveXObject) { created
isIE = true;
req = new ActiveXObject("Microsoft.XMLHTTP");
}
}
function validateUserId() {
initRequest();
req.onreadystatechange = processRequest;
if (!target) target = document.getElementById("userid");
var url = "validate?id=" + escape(target.value);
req.open("GET", url, true);
req.send(null);
}
2. An XMLHttpRequest object is
configured (cont.)
var req;
function initRequest() {
if (window.XMLHttpRequest) {
req = new XMLHttpRequest();
} else if (window.ActiveXObject) { Set Callback function
isIE = true;
req = new ActiveXObject("Microsoft.XMLHTTP");
}
}
function validateUserId() {
initRequest();
req.onreadystatechange = callBack;
if (!target) target = document.getElementById("userid");
var url = "validate?id=" + escape(target.value);
req.open("GET", url, true);
req.send(null);
}
Anatomy of an AJAX Interaction
Data Validation Example
3. XMLHttpRequest object makes an
asynchronous request
function initRequest() {
if (window.XMLHttpRequest) {
req = new XMLHttpRequest();
} else if (window.ActiveXObject) {
isIE = true;
req = new ActiveXObject("Microsoft.XMLHTTP");
}
} requested URL is set
function validateUserId() {
initRequest();
req.onreadystatechange = processRequest;
if (!target) target = document.getElementById("userid");
var url = "validate?id=" + escape(target.value);
req.open("GET", url, true);
req.send(null);
} Make request to url asynchronously
Anatomy of an AJAX Interaction
Data Validation Example
4. Server component process request
function setMessage(isValid) {
var mdiv = document.getElementById("userIdMessage");
if (isValid == "true") {
mdiv.innerHTML = "<div style=\"color:green\">Valid User Id</ div>";
} else {
mdiv.innerHTML = "<div style=\"color:red\">Invalid User Id</ div>";
}
}
</script>
<body>
<div id="userIdMessage"></div>
</body>
Current Issues with AJAX
• JavaScript
> inconsistent support among browsers
> requires cross browser testing
> code is visible to a hacker
> Can be difficult to develop, debug, and maintain
> automatic testing is hard
AJAX Toolkits and
Frameworks :
Dojo Client Side
JavaScript Library
What is Dojo Toolkit?
• Open Source set of JavaScript libraries
• Simplifies adding AJAX into web pages!
• Major industry support (Sun, IBM, AOL)
• http://dojotoolkit.com/
• Server side technology independent
source: dojotoolkit.org
Dojo Toolkit Libraries
• dojo.io: AJAX-based
communication with the
server
• dojo.event: unified event
system
• dojo.widget Widget
framework
• dojo.dom: DOM manipulation
routines
• string, json: utility routines to
make JavaScript easier to
use.
Dojo Pro's And Con's
• Pro's
> You can use it with any server side technology
> Make Ajax easier, takes care of browser problems
> Can mix with other Javascript frameworks
• Con's
> Developer still has to learn some JavaScript
AJAX Toolkits and
Frameworks :
jMaki
What is jMaki
• jMaki is a lightweight AJAX Framework
> Make javascript accessible to JSP, JSF, PHP,
Ruby/JRuby and Phobos
• “AJAX” in a tag
• Widget model
> Leveraging popular toolkits: dojo, Yahoo, Google,
Scriptaculous, ...
• Layout
• Server Model
> Mashup with outside services
Publish/Subscribe
https://ajax.dev.java.net/publishsubscribe.html
Publish Example
Tao Michael Li
Technology Evangelist
Sun Microsystems, Inc.
57
57