You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@struts.apache.org by Greg Pelly <gp...@esri.com> on 2005/09/17 02:39:50 UTC
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: user-unsubscribe@struts.apache.org
For additional commands, e-mail: user-help@struts.apache.org
Re: Struts ActionForms and DWR/AJAX
Posted by Laurie Harper <la...@holoweb.net>.
Michael Jouravlev wrote:
> On 9/17/05, Laurie Harper <la...@holoweb.net> wrote:
>>Correct, Struts makes no distinction between GET and POST requests
>>(other than transparently doing the extra request parsing for a POST).
>
> What do you mean by "extra request parsing for a POST"? Pulling
> parameters from request body instead of the parsing URL from the
> header?
Exactly.
> About POST and GET: if I am not mistaken, user agent is required to
> ask for confirmation if result of POST is reloaded. On the other hand,
> I am not sure that this is the spec requirement, maybe not, need to
> verify.
Yeah, but that's a browser behaviour and doesn't effect how the request
is actually handled once the browser submits it.
> The sure difference is that redirecting from POST to POST requires
> confirmation, while redirecting from POST to GET - does not.
Again, that's a browser behaviour thing rather than an issue with how
the request gets processed. It's good to keep in mind, though :-)
L.
---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
For additional commands, e-mail: user-help@struts.apache.org
Re: Struts ActionForms and DWR/AJAX
Posted by Michael Jouravlev <jm...@gmail.com>.
On 9/17/05, Laurie Harper <la...@holoweb.net> wrote:
> Frank W. Zammetti wrote:
> > 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?).
>
> Correct, Struts makes no distinction between GET and POST requests
> (other than transparently doing the extra request parsing for a POST).
What do you mean by "extra request parsing for a POST"? Pulling
parameters from request body instead of the parsing URL from the
header?
About POST and GET: if I am not mistaken, user agent is required to
ask for confirmation if result of POST is reloaded. On the other hand,
I am not sure that this is the spec requirement, maybe not, need to
verify.
The sure difference is that redirecting from POST to POST requires
confirmation, while redirecting from POST to GET - does not.
Michael.
---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
For additional commands, e-mail: user-help@struts.apache.org
Re: Struts ActionForms and DWR/AJAX
Posted by Laurie Harper <la...@holoweb.net>.
Frank W. Zammetti wrote:
> 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?).
Correct, Struts makes no distinction between GET and POST requests
(other than transparently doing the extra request parsing for a POST).
L.
---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
For additional commands, e-mail: user-help@struts.apache.org
Re: Struts ActionForms and DWR/AJAX
Posted by "Frank W. Zammetti" <fz...@omnytex.com>.
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" <gp...@esri.com>
> To: "Struts Users Mailing List" <us...@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: user-unsubscribe@struts.apache.org
> For additional commands, e-mail: user-help@struts.apache.org
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
> For additional commands, e-mail: user-help@struts.apache.org
>
>
>
>
>
--
Frank W. Zammetti
Founder and Chief Software Architect
Omnytex Technologies
http://www.omnytex.com
---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
For additional commands, e-mail: user-help@struts.apache.org
Re: Struts ActionForms and DWR/AJAX
Posted by Martin Gainty <mg...@hotmail.com>.
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" <gp...@esri.com>
To: "Struts Users Mailing List" <us...@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: user-unsubscribe@struts.apache.org
For additional commands, e-mail: user-help@struts.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
For additional commands, e-mail: user-help@struts.apache.org
Re: Struts ActionForms and DWR/AJAX
Posted by Joe Germuska <Jo...@Germuska.com>.
I've just recently explored DWR for the first time, and I was quite
impressed. However, my take was that of the authors of the page you
cited -- there's really not much rationale that I can see for doing
anything specifically with Struts and DWR together.
Good practice for a Struts application would be for your Struts
action classes to contain a minimum of business logic, and to
primarily concern themselves with converting strings, the only kind
of request parameters which can be submitted by HTTP, into whatever
form is appropriate to your Struts-agnostic application layer.
If you have this kind of organization, than DWR fits at the same
layer as Struts, and given that it has full access to the
Servlet-level execution context, it shouldn't need anything specific
from Struts; your remoted object would do the same thing an action
does, passing values into your business layer.
The ability for DWR to remote beans defined with Spring makes this
even easier, because you can make it very easy for the remoted object
to reference these application-layer service beans. (You could
always look them up in a ServletContext or something, but the Spring
bean lookup is much more elegant.)
The one concession to Struts that I made with my implementation (an
"add to cart" feature) was to subclass the DWR ExecutionContext
object to expose a Struts ActionContext object (actually, my own
subclass of ActionContext) - this can easily be made any time a
request, response, and servlet context are available, and it allows
me to maintain a consistent guard against access to session and
request scoped objects, rather than having to spread a bunch of
references to String constant attribute names through out my code.
As far as I can tell, DWR and Struts will co-exist peacefully
together, but without much concern for each other. Is there a
specific way in which you need DWR to use an ActionForm? If there
is, that may be a sign of a place where you should re-organize the
responsibilities of various classes in your application.
Joe
At 5:39 PM -0700 9/16/05, Greg Pelly wrote:
>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: user-unsubscribe@struts.apache.org
>For additional commands, e-mail: user-help@struts.apache.org
--
Joe Germuska
Joe@Germuska.com
http://blog.germuska.com
"Narrow minds are weapons made for mass destruction" -The Ex
---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
For additional commands, e-mail: user-help@struts.apache.org