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.
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Read now
Unlock full access