| By Kris Vishwanathan | Article Rating: |
|
| August 9, 2007 01:00 PM EDT | Reads: |
24,442 |
The Struts Framework from Apache is a very popular, robust Web application framework. Many corporate companies have deployed tons of Web applications using Struts. And they hit the ground with abundant technical resources. They can develop newer applications quickly. Portal implementations offer a new challenge by introducing new frameworks and APIs. To leverage existing assets and skills, WebSphere Portal supports the Struts Portlet Framework so Struts Web applications can be easily migrated to a portal.
AJAX, or Asynchronous JavaScript and XML, is a new happening technology to make Web applications function like client/server applications. I mean Web pages triggering requests based on events (asynchronously) that refresh only specific parts of a page as opposed to refreshing the whole page.
The Struts Framework
There's tons of information on Struts, AJAX, and the Struts Portlet Framework available on the Web. In this article I'm going to provide a brief introduction to these topics; for more details check out the resources section.
The Struts Framework is an implementation of the MVC architecture, with Model being the business logic represented using JavaBeans, EJBs, etc., View the presentation layer represented by using JSPs, ActionForms, and tag libraries, and Controller the ActionServlet and Action classes (see Figure 1).
Struts Control Flow
Here is the typical request-response cycle for the Web application using Struts:
- The client requests a path matching the Action URI pattern.
- The Web container passes the request to the ActionServlet.
- The ActionServlet looks for the Struts configuration file, if this application has multiple modules it looks for the appropriate mapping for the given path in any of the Struts configuration file.
- If the mapping specifies a form bean, ActionServlet looks to see if one exists or it creates one.
- Once the form bean is created, ActionServlet populates values from the HTTP request. If the mapping has a validate property as true, ActionServlet invokes the validate method on the form bean. If the validation fails, the control flow ends there.
- If the Struts configuration file specifies action mapping then the appropriate action class 'execute' method is invoked with an instantiated form bean as a parameter.
- The Action may call other business objects and repopulate the form bean with the latest values and other business functions as needed.
- Based on where you want to send the control next, the Action reads ActionForward and the Action URI from the Struts configuration file and returns to the ActionServlet.
- If the ActionForward is a URI to the JSP to display the page, the control flow ends by sending the output to the browser or if it's forwarded to another Action URI the above flow starts again.
AJAX Control Flow
- A Web page sends its requests using an XMLHttpRequest object and JavaScript function, which handles talking to the server.
- Nothing has changed for the Web application server; it still responds to each request, the way it did it before.
- The server's response only has the data it needs in the XML form, without any markup or presentation.
- The JavaScript dynamically updates the Web page without redrawing the whole page.
- Most of the page doesn't change, only the parts of the page that need to change is updated, and that asynchronously.
A portlet processes and renders differently than a servlet. A servlet will do all its processing in the service method, while the portlet will divide action processing and rendering into two separate methods, hence portlet processing is defined as a two-phase approach. Figure 3 explains the two-phase processing approach of a Struts portlet. To invoke actions in the rendering phase there is a new interface called IStrutsPrepareRenderer. For more details see Executing Struts actions during the render phase of IBM WebSphere Portal.
IBM supports Struts Portlet Framework for both IBM API and JSR 168 API portlet containers. Users can easily migrate existing Struts applications to Struts portlet applications using either of the portlet's APIs. For more information on migrating and developing newer applications using the Struts Portlet Framework see the Portal Info Center.
Struts Portlets with AJAX
Though AJAX isn't the right solution for every Web application, there's increasing curiosity and enthusiasm among organizations to explore its benefits and see how it works for their applications. AJAX isn't new, but it's all on the client side and making it work with different server-side frameworks is a challenge. This article is a result of my client experience in developing Struts portlet applications with AJAX. In the sections above I briefly described Struts and AJAX. In the sections below I'll describe some of the challenges faced during implementation. To develop AJAX applications there are several toolkits such as Google Web Toolkit (GWT), DOJO, AJAX Faces, and JSON, but for simplicity's sake we chose a plain vanilla implementation.
The tricks to rendering content asynchronously using AJAX has more to do with JavaScript and XMLHttpRequestObject than any server-side technology, however, getting the blend of AJAX working with server-side frameworks involves careful design and architectural thinking.
Making asynchronous calls to the server using AJAX best fits a portal scenario with different portlets representing different back-end application views. However, this feature isn't supported with portlet URLs since each response from the portlet container represents a portal page with different portlets with different window states and modes. Given this limitation, the alternative we have is the XMLHttpRequest object calling a servlet from a servlet container as depicted in Figure 4.
To demonstrate the above scenario I have used the simple downloadable example shown below.
As in Figure 5 and Figure 6, when the user clicks on the menu items, the right-side blue box items get refreshed without unloading the whole page.
Below are some of the challenges we had and I'll explained how we addressed them.
Published August 9, 2007 Reads 24,442
Copyright © 2007 SYS-CON Media, Inc. — All Rights Reserved.
Syndicated stories and blog feeds, all rights reserved by the author.
More Stories By Kris Vishwanathan
Kris Vishwanathan is an IT Architect who has been with IBM since 2003. He worked as a senior developer and architect for IBM Systems and Technology Group before joining IBM Software Services for Lotus at the end of 2004. He has been part of the delivery team implementing WebSphere Portal and Web Content Management (WCM) solutions. In addition to architecting solutions for clients, he also sets up portal production environments involving portal clustering, Tivoli Access Manager, LDAP, user registry configurations, and portlet development using JSR168, JSF, IBM API, and WCM API. He is an IBM Certified WebSphere Portal System Administrator and Solution Developer.
![]() |
suwei 04/07/08 10:11:46 AM EDT | |||
where does download the strutsAJAXportlet.war ? |
||||
![]() |
Chrisf 11/13/07 01:17:01 PM EST | |||
Hi, Can we get the source code for this article please? Thanks. |
||||
![]() |
sharkbob 05/16/07 07:53:23 AM EDT | |||
I cannot find a reference to the war file thanks |
||||
- Cloud Computing on Gartner's Top 10 List and SYS-CON Events' 2010 Calendar
- Confessions of a Ulitzer Addict
- IBM Hardware Chief, Intel VC Exec Arrested in Insider Trading Scam
- My Thoughts on Ulitzer
- Tactical Cloud Computing Panel at 1st Annual GovIT Expo
- Ulitzer.com Named Exclusive "New Media" Sponsor of Cloud Computing Conference & Expo
- Moving Your RIA Apps into the Cloud: Seven Challenges
- Adobe’s Aiming ColdFusion at Multiple Clouds
- Windows 7 – Microsoft’s First Step to the Cloud
- Ulitzer Provides a Powerful Social Journalism Platform
- Jill Tummler Singer, Deputy CIO of CIA, Keynotes at GovIT Expo
- Open Source Mobile Cloud Sync and Push Email
- Practical Approaches for Optimizing Website Performance
- The Difference Between Web Hosting and Cloud Computing
- Cloud Computing on Gartner's Top 10 List and SYS-CON Events' 2010 Calendar
- Ajax in RichFaces 3.3, JSF 2 and RichFaces 4
- Confessions of a Ulitzer Addict
- IBM Hardware Chief, Intel VC Exec Arrested in Insider Trading Scam
- My Thoughts on Ulitzer
- Tactical Cloud Computing Panel at 1st Annual GovIT Expo
- US Post Office Hops a Ride on NetSuite’s Cloud
- Ulitzer.com Named Exclusive "New Media" Sponsor of Cloud Computing Conference & Expo
- WPF Controls by DevExpress
- Moving Your RIA Apps into the Cloud: Seven Challenges
- Building a Drag-and-Drop Shopping Cart with AJAX
- What Is AJAX?
- Google Maps! AJAX-Style Web Development Using ASP.NET
- Flashback to January 2006: Exclusive SYS-CON.TV Interviews on "OpenAjax Alliance" Announcement
- AJAXWorld Conference & Expo to Take Place October 2-4, 2006, at the Santa Clara Convention Center, California
- AJAX Sponsor Webcasts Are Now Available at AJAXWorld Website
- How and Why AJAX, Not Java, Became the Favored Technology for Rich Internet Applications
- "Real-World AJAX" One-Day Seminar Arrives in Silicon Valley
- AJAXWorld University Announces AJAX Developer Bootcamp
- AJAX Support In JadeLiquid WebRenderer v3.1
- Where Are RIA Technologies Headed in 2008?
- Struts Validations Framework Using AJAX





































