O'Reilly logo

Ajax Hacks by Bruce W. Perry

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Chapter 5. Direct Web Remoting (DWR)for Java Jocks

Hacks 4349

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.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required