Brent,
Here's a few more details about my experience with AJAX.
Right from the start, I could see that Action classes just weren't a very good fit for AJAX. There's a lot of unnecessary stuff in them that AJAX doesn't need to worry about. Also, the whole idea of returning an ActionForward doesn't fit at all, since AJAX returns an XML response, rather than a JSP. This left me finding ways around the Struts framework, such as returning a null ActionForward and finding my own way to return a response. When I find myself doing work to get around a framework, that's a sign that it doesn't fit, and sends me searching for something else.
I already had some objects following the Business Delegate
pattern, so at first I tried calling methods from these objects directly from the DWR framework. This worked great, but then I began to realize something: There was no security on these methods. Anyone with some savvy could construct an HTML page with some JavaScript and access any of the methods I had exposed to the DWR framework.
I then created some wrappers for these Business Delegates. These wrappers just verify that the users are valid, logged-on users, and they have authority to do what they're trying to do and then passes the call on to the Business Delegate. I now call the wrappers from AJAX, and that seems to solve the security problem.
Another reason I went with the DWR framework for AJAX rather than trying to pound the square peg of AJAX into the round hole of Struts is that DWR totally does all the low level AJAX dirty work for me. All I have to do is define which classes and methods I want DWR to call, and which beans might be passed by those calls, and DWR provides me with a JavaScript function that has the same signature as my
Java method. When I call that function, DWR handles all the marshalling and unmarshalling of XML, and magically calls my Java method on the server, returning the response to a JavaScript function that I supply. If I try to call a Struts Action class through AJAX, I have to do everything myself.
I find that this mix of Struts and DWR works pretty well. Both Struts and DWR call some of the same Business Delegate classes, so there's really not much duplication of code. Security checking is about the only area where code is duplicated, but later I may re-factor some of my security checking code into common classes that can be called by either Struts or DWR.
I still firmly believe that most web application problems are best solved by the traditional "display a page, read a form" approach, and of course Struts works great for those pages. There are a few problems that AJAX handles much better, and for those tasks, I use AJAX and DWR.