Ajax and DWR
For a while, web application development has been a little stagnant. Developing for the
browser has offered the option of creating simple HTML interfaces that work on any browser or
operating system, or taking advantage of specific browser functionality to add more dynamic
behavior at the cost of vendor lock-in or non-portability. The former type of application was
more suited to an Internet audience and the latter more common in the intranet where organi-
zations typically control the desktop software.
But things are changing for a variety of reasons. For one, browsers of all types now have
more commonality in the standards that they implement than at any time in the past. Secondly,
XMLHttpRequestwas adopted as standard. Combined, they make cross-platform dynamic
browser solutions a real possibility in the shape of Ajax: Asynchronous JavaScript and XML.
With Ajax, you retrieve from the server only the data that you actually need, and you don’t
have to load a whole page, much of which might be the same as was fetched before. That
means we can post and retrieve data to and from the server afterthe page has loaded.
In the last 6 to 12 months, loads of toolkits, frameworks, utilities, and applications have
sprung up, all based on Ajax. DWR(http://www.getahead.ltd.uk/dwr), which stands for Direct
Web Remoting, is one such toolkit. It provides a bunch of commonly used functions that your
web application will inevitably need anyway to be able to make use of Ajax, and therefore it
saves you from a lot of typing. For all self-respecting coders, this is never a bad thing, of
course.
Spring and DWR
What does this all have to do with Spring MVC, you might be wondering. Well, not a great deal
directly, but this is such a popular technology right now that we thought it would be interesting
to include a few pages on how you might enhance your Spring web applications through the use
of DWR. It would even be possible, if you really wanted to try, to replace the majority of MVC
functionality with Ajax/DWR, but we feel that a blend of the two offers the most promise.
DWR works, as the name suggests, by making server-side objects available to your client-
side JavaScript functions. That means you have the ability to call methods on those objects
from within your JavaScript functions and work with the results. DWR handles the conversion
of the server-side objects by dynamically creating JavaScript objects that implement the same
interface. When you call the methods on the JavaScript object, DWR proxies the call to the
server and converts the returned object (if any).
377
APPENDIX B
■ ■ ■
584X_Ch14_AppB_FINAL 1/30/06 12:55 PM Page 377