Chapter 5. Direct Web Remoting (DWR)for Java Jocks
What if you want to work with Ajax without having to deal with
programming the XMLHttpRequest
object?
An open source toolkit called Direct Web Remoting (DWR) provides a software layer built on
top of this object, completely insulating web page developers from
directly programming the request object. DWR also allows Java developers
to create Java classes, then use the server-side Java objects from within
JavaScript client code (thus the moniker “Web Remoting”).
One advantage of DWR is that you can forget about the boilerplate
code we have used in other hacks to get the XMLHTTP
and XMLHttpRequest
objects working. This framework
also includes easy techniques for populating web page widgets with server
data, while largely removing the required knowledge of Document Object
Model programming. The one caveat to using DWR is that you must
use a Java-based server-side solution, because DWR works with
Java servlets and objects behind the scenes.
DWR provides a neat mapping between Java objects and JavaScript code. In other words, you can set up the logic for your application using Java objects on the server, then call those objects’ methods with JavaScript code when need be. This is called remoting your objects, or making remote Java method calls with JavaScript objects that are bound to the Java objects on the server. This chapter’s first hack explains the process for setting up DWR and integrating it into a web application.
Get Ajax Hacks now with the O’Reilly learning platform.
O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.