Thursday, November 3rd, 2005
Struts is the grand-daddy of Java web frameworks, and although the buzz has moved on to other Java web frameworks like JavaServer Faces, WebWork, Tapestry, … a lot of people are still writing Struts applications.
Paul Browne has written an introductory article called Sprinkle Some AJAX Magic in Your Struts Web Application.
The article focuses on the Ajax client side, rather than integration with Struts.
Designing AJAX into Your Application
- To avoid duplicated code, it can often be better to use the same Struts Action and JSP for the initial request (i.e., show full page) and the AJAX (update part of page) requests.
- Within the common Action (controller) class, decide which sections of the JSP page (all of the JSP or only part of it) need to be sent to the browser. By setting flags in either the web server session or ActionForm, the JSP page knows which sections need to be rendered.
- Within the JSP, use Struts
or JSTL tags to decide if we need to render a section of HTML or not.
An updated version of this project, with AJAX enabled, can be downloaded here: struts-Ajax.zip
Posted by Dion Almaer at 2:53 pm