Thanks for the props Martin! :)

Greg... one common misconception about AJAX is that it needs to involve XML. It doesn't (ok, it probably shouldn't be called AJAX in that case, AJA? perhaps...)

Note that there is nothing special about a form being submitted to a Struts Action... The Struts HTML taglib hides some of the details from you, but underneath it's a perfectly ordinary HTML form that results in a perfectly ordinary HTTP POST request. On the server, the parameters are retrieved and the ActionForm populated, if applicable, and your Action called.

XMLHttpRequest does exactly the same thing when you get right down to it: it's just an ordinary HTTP request too.

The pertinent point is that you can specify the method to use (GET or POST) for the object. Take a look here:

http://www.devx.com/DevX/Tip/17500

This is a quick tip that shows how to POST with XMLHttpRequest. If you were to use this example and target an Action mapping, you should find that the ActionForm does get populated, and Struts works exactly as it always does. Well, except for what's returned of course... there has to be some client-side script that knows how to interpret whatever the Action (or JSP) returns. But as far as Struts is concerned, it's business as usual.

Further, I'm almost positive if you were to simply do a GET to an Action mapping with XMLHttpRequest, assuming the parameters you include in the query string match what would be POSTed from a form, it should work the same (never tried that... anyone else know differently?).

But regardless of that... I have no experience with DWR, so I can't give you specifics... But, assuming you can make it do as the above link demonstrates, then as far as Struts is concerned, an AJAX request is no different from a "normal" request. You can have your auto-population of ActionForm and DWR too.

Alternatively, you might consider AjaxTags in Java Web Parts:

http://javawebparts.sourceforge.net/javadocs/index.html

It's definitely not the same as DWR and might not fit your requirements, but you can't expect me to not plug my own creation, can you?!? :)

Frank

Martin Gainty wrote:
Greg-
check out Frank Zammetti's tutorial for Asynchronous JavaScript with XML
http://www.omnytex.com/articles/xhrstruts/
A most excellent primer..
HTH,
Martin
----- Original Message ----- From: "Greg Pelly" <[EMAIL PROTECTED]>
To: "Struts Users Mailing List" <user@struts.apache.org>
Sent: Friday, September 16, 2005 8:39 PM
Subject: Struts ActionForms and DWR/AJAX


I am thinking about migrating an application using Struts and
ActionForms to use the DWR implementation of AJAX.  I stood up a simple
DWR sample and I'm realizing that it may not be possible to integrate
DWR with ActionForms -- DWR makes requests through the "backdoor" (ie,
XMLHttpRequest), rather than by submitting a form created by
<html:form>, so the Struts ActionForm does not get populated.  In fact,
request.getParameterNames() returns an 0-element enumeration, which
makes me think it may not be possible at all.

Does anyone have experience with ActionForms and AJAX? I did a quick
Google search and found this article:

http://getahead.ltd.uk/dwr/server/struts

Any help would be appreciated.

Greg

---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]


---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]






--
Frank W. Zammetti
Founder and Chief Software Architect
Omnytex Technologies
http://www.omnytex.com


---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to