| By Kris Vishwanathan | Article Rating: |
|
| August 9, 2007 01:00 PM EDT | Reads: |
24,449 |
JavaScript Objects
AJAX applications use the XMLHttpRequest Object and client-side JavaScript, and as these applications become more complex it becomes difficult to maintain the code using plain JavaScript functions. Object-oriented programming is ideal and proven for such complex applications. JavaScript offers many different ways of defining objects, but it's not a full-fledged object-oriented programming language. There are several efforts by different people aimed at providing workarounds for object-oriented programming features such as inheritance, reflection, and interfaces using JavaScript.
JSON (JavaScript Object Notation) provides guidance on JavaScript object notation. In our example, we have used JSON guidelines and defined all the JavaScript functions as objects. We have also defined all the functions as external js files so that all the client-side logic is kept modular and separate from the JSP file, following portlet best practices.
Here is the JavaScript code snippet from the downloadable sample application defining an object and calling the function as object instance methods.
if (typeof(contentHelper) === 'undefined'){
var contentHelper = [];
}
contentHelper['<%=contentAppNamespace%>'] = new ContentHelper({
namespace : "<%=contentAppNamespace%>",
urlContextPath : "<%=request.getContextPath()%>"
});
I defined all other JavaScript functions in different js files. Below is the definition of the 'ContentHelper' function.
function ContentHelper(params){
//Parameter Variables
if (!params){
alert('Missing parameters while instantiating!');
return {};
}
if (typeof(WebFormUtils)=='undefined'){
alert("The utils package is not included!");
return;
}
var namespace = params.namespace;
var urlContextPath = params.urlContextPath;
var formUtils = new WebFormUtils({
namespace : namespace
});
var AJAXurls = new AJAXURLs({
namespace : namespace,
urlContextPath : urlContextPath
});
var AJAXEngine = new AJAXEngine({
redirectHandlerFunction : formUtils.handleAJAXRedirect,
retryPromptMessage : "Warning, there was a problem
during an attempt to communicate with the server\n"
+
"Would you like to retry? (It's recommended
to wait a bit first)\n" +
"If the problem persists, please contact Help
Desk",
autoRetries : 2,
retryDelay : 10000
});
.....
.....
}
The object/function above in turn instantiates other objects such as AJAXUrls and AJAXEngine.
Handling Namespace with an AJAX Response
As specified in Figure 3, Struts portlets make asynchronous AJAX requests to servlets. Servlets process the request and send the response back to the client, which in turn is suppose to refresh certain parts of the portlet JSP page. Portlets being namespace-aware, it's very important that any Web page refresh be namespace-aware. Unfortunately, the servlet is not aware of the portlet namespace. To resolve this issue we have passed namespace as a parameter for every AJAX request so that the servlet response can prefix all object ids with the appropriate namespace.
Published August 9, 2007 Reads 24,449
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 |
||||
- Kindle 2 vs Nook
- 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
- 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
- Kindle 2 vs Nook
- 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
- Ulitzer.com Named Exclusive "New Media" Sponsor of Cloud Computing Conference & Expo
- US Post Office Hops a Ride on NetSuite’s Cloud
- Moving Your RIA Apps into the Cloud: Seven Challenges
- Adobe’s Aiming ColdFusion at Multiple Clouds
- 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





































