struts-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Wille Faler <wille.fa...@infonatural.com>
Subject Integrating DWR and Struts2 for true "MVC" of snippets of web-pages
Date Wed, 25 Oct 2006 22:59:19 GMT
Hi.
I raised the question today on Don Browns blog about being able to have
integration between Struts2 and DWR, to get a full MVC model if you only
want to re-render a snippet of a web-page.
I am not sure if this has been discussed previously, but Don encouraged
me to send my ideas if I had any, so here goes:
When I have done AJAX-based stuff, 9 times out of 10, all I really want
to do i execute some business logic, and re-render a portion of a page.
This would seem to fit well with a traditional MVC-approach, with the
exception that I don't want to re-render the full page.

Earlier this year, I implemented such a simple framework, basically
using Webwork2/XWork and DWR, adding some code to glue it all together.
It consists of the following things:
- Some generic JavaScript that can interpret parameters (either from a
form or URL) into a Map of parameters, akin to what Webwork uses.
- A Controller that is called by DWR, taking the Map, a callback-target
(in the web-page) and the name of an action as its arguments. This
Controller then invokes an xwork ActionProxy to invoke the Action.
- Custom Result-implementations for getting JSP-elements defined in the
xwork results. These results use the DWR
WebContextFactory.get().forwardToString() functionality, to get the
resulting JSP-snippet as a String.
- Said Result can then be sent back by the Controller through DWR, which
is then handled by generic JavaScript and rendered to the predefined
callback-target on the page.
- When using forms, it can also do AJAX-based validation which makes use
of proper Xwork-validation.

As I said, I have already written code for this, it is quite compact and
only a few hundred lines (11 implementation classes + generic JavaScript
+ dwr config), so obviously this integration is quite easy to create. I
would love to see something similar within the upcoming Struts2!
I haven't attached the code to this mail, but it is available for
download here: www.infonatural.com/ajax-mvc.zip (including
jar-dependencies and some unit-tests, 3.6mb).

If anyone wants to pick the code for ideas, or adapt it, feel free to do
so as long as you retain the original @author comments as part of it (I
am the sole copyright holder of the code, and you may use it under the
ASF if you want).
It would probably need some minor improvements to make it more in line
with the rest of the Struts2-code (so tags work etc), as I only did the
code originally for my needs and didn't bother doing more than I needed
at the time.

I apologise if this or something similar is already part of Struts2, but
I got the impression that it may not be.

regards
Wille Faler


---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@struts.apache.org
For additional commands, e-mail: dev-help@struts.apache.org


Mime
View raw message