Struts has been one of the major Java Frameworks for building Web applications for a number of years. Ajax is the latest buzz on building dynamic, user friendly web interfaces. How can Java Developers add the power of Ajax to these existing Struts Applications without having to tear out the existing code?
- Posted by: paul browne
- Posted on: October 30 2005 09:06 EST
Sprinkle Some AJAX Magic in Your Struts Web Application, hosted on java.net, shows how.
How many ServerSide readers are actually developing using Ajax? Do they feel that it is living up to the hype? Are readers inclined to extend their existing (Struts based) apps, or go for a complete rebuild using something like DWR (Direct Web Remoting), Dojo, or other such frameworks?
- Java.net Article on Using Ajax with Struts by Vitaly Shevchuc on October 31 2005 07:45 EST
- Another option for the article by Elan H on October 31 2005 13:26 EST
- Silly question by M L on October 31 2005 17:54 EST
- The AJAX hypo is far reached by P s on November 14 2005 04:16 EST
- DWR and Struts? by Eric Ma on December 31 2005 10:51 EST
The idea is good, but not too fresh ;)
Check out this also from Coldtags suite:
Thanks for suggesting AjaxAnywhere.
In my opinion, one of the many Ajax Libraries that have sprung up will win out and become a de-facto standard, similar to what Struts was for the previous generation of Web Applications.
The focus of the article was adding Ajax to existing applications , without having to add or replace libraries. Where you have choice of moving to new libraries, the projects like AjaxAnywyere and AjaxTags are worth taking a look at - several others , including DWR are mentioned in the article.
I just started playing around with AJAX to do something similar to the example in the article. The solution I choose was not mentioned in the article and it was to have the AJAX call return the HTML for the table. That way I don't need to have any messy Javacript code to parse the response. And I reuse the same JSP logic that created the table initially. For my needs at least this approach appears to work well and I don't have the need for the other frameworks as of yet.
btw, I was designing a treeview widget where a tree folder could be lazy-loaded.
Looked at doing it that way - the difference between the two approaches is that the article can use an asynchronous call, so is more robust where there the network is not guaranteed (ie most internet and many intranets).
I did a prototype like this. The AJAX call his the same Struts actions forwarding to JSPs and JSP fragments, returning the generated HTML to the XmlHttpRequest object. The client then just had to do element.innerHTML = req.responseText;
However, we're now using a portal, and calling a portlet is different from calling an AJAX servlet, so reusing the same code just won't work without a lot of kludging.
One can also go through the following article:
In the tutorial, After posting to the struts action, the struts action forwards to index.jsp [ view ]
I was under the impression, the action should refresh only a part of the page using Ajax. In this the view itself is bit different.
It's a good question.
To keep things simple , the action forwards to the same Index.jsp to display the page. The Page , using logic tags , decides which sections needs displayed.
It would be possible to forward to a different page as long as the <Span> tags are the same on both pages. The article mentions this (near the end), but does not go into detail.
What is a POST back pattern right from ASP.NET
Do we really need a Struts?
Many people have been asking the question 'do we need Struts' for quite a long time , even though it has served the Java Community Well :-)
Struts is a Java - Web implementation of the Model-View-Controller pattern. I wouldn't be surprised if it was close to an ASP.Net pattern, given the amount of cross-pollination between the two.
Has anyone used DWR to call Struts Action classes (or a thin wrapper on top of it)? We have a lot of existing Struts code and we would like to leverage it.