Skip to main content link. Accesskey S
  • Log In
  • Help
  • IBM Logo
  • WebSphere Portal Family wiki
  • All Wikis
  • All Forums
  • Home
  • Product Documentation
  • Community Articles
  • Learning Center
  • IBM Redbooks
Community Articles Product Documentation Learning Center IBM Redbooks This category IBM Redbooks: Building a Sample Website Using IBM Web Content Manager 7.0 IBM Redbooks: Building and Implementing a Social Portal IBM Redbooks: Developing Exceptional Multi-Channel Web Experiences V7: IBM Web Content Manager Product Documentation V7: IBM WebSphere Portal Enable for z/OS Product Documentation V7: IBM WebSphere Portal Express Product Documentation V7: WebSphere Portal Product Documentation V8: IBM Web Content Manager Product Documentation V8: IBM WebSphere Portal Express Product Documentation V8: IBM WebSphere Portal Product Documentation (includes z/OS) Custom Search Scope...
Search
Community Articles > IBM Accelerators for WebSphere Portal > IBM Mobile Portal Accelerator > Implementing AJAX with IBM Mobile Portal Accelerator
  • New Article
  • Share Show Menu▼
  • Subscribe Show Menu▼

About the Original Author

IBM contributorMitul Kundalia
Contribution Summary:
  • Articles authored: 3
  • Articles edited: 0
  • Comments Posted: 0

Recent articles by this author

Creating a custom IBM WebSphere Portal portlet to search across IBM Web Content Manager, Connections, and Lotus Quickr

This article shows you how to create a custom search portlet in IBM WebSphere Portal that searches IBM Web Content Manager, IBM Connections, and IBM Lotus Quickr using REST APIs.

Implementing AJAX with IBM Mobile Portal Accelerator

This article demonstrates an example of how to use Asynchronous JavaScript + XML (AJAX) with a JSR 286 portlet deployed on IBM Mobile Portal Accelerator 6.1.

Customizing IBM Web Content Manager menu components

The menu component is widely used to search and display content in an IBM Web Content Manager (WCM) system; however, using the conventional way of displaying data in the UI, users are are unable to tweak it according to their needs. This article shows how to customize the menu components using ...

Community articleImplementing AJAX with IBM Mobile Portal Accelerator

Added by IBM contributor Mitul Kundalia | Edited by IBM contributor Leslie Gallo on April 16, 2012 | Version 6
  • Edit
  • More Actions Show Menu▼
Rate this article 1 starsRate this article 2 starsRate this article 3 starsRate this article 4 starsRate this article 5 stars
expanded Abstract
collapsed Abstract
This article demonstrates an example of how to use Asynchronous JavaScript + XML (AJAX) with a JSR 286 portlet deployed on IBM Mobile Portal Accelerator 6.1.
Tags:
ShowTable of Contents
HideTable of Contents
  • 1 Introduction
    • 1.1 Prerequisites
  • 2 Additional requirements
  • 3 Implementing the code
  • 4 Conclusion
  • 5 Resources
  • 6 About the author

Introduction


The motivation behind writing this article is that I haven't been able to find much information on using Asynchronous JavaTMScript + XML (AJAX) with IBM® Mobile Portal Accelerator (MPA) 6.1. Moreover, I've heard from various groups of people (Developers, Product Teams, et al.) that, when using MPA, they prefer to perform server-side operations rather than client-side operations.

However, with the wide availability of new smartphones in the market, it doesn't make sense not to use their rich browser features supporting Web 2.0.

Recently I was involved in a Proof-of-Concept exercise around MPA in which the customer wanted their IBM WebSphere® Portal application to be available in mobile handsets. They were targeting smartphones (iPhone, Android, BlackBerry), so they needed a mobile portal that could provide a Web 2.0-like effect (AJAX call, run JavaScript event, and refresh HTML based on the AJAX response).
This article explains how you can use AJAX with a JSR 286 portlet deployed on Mobile Portal Accelerator 6.1.

Prerequisites


The following development environment is required for this exercise:
  • Mobile Portal Accelerator 6.1
  • IBM Mobile Portal Toolkit (MPTK) 6.1
  • IBM Rational® Application Developer (RAD) 7.5
  • JSR 286
  • PhoneGap/Android simulator
  • XML-based Device Independent Markup Extensions 1 (XDIME1)

Additional requirements


For AJAX to work, your mobile device browser should support JavaScript. To enable JavaScript in MPA, follow the steps below (as outlined in the WebSphere Portal Family wiki article, “Using javascript in MPA with XDIME1 and XDIME2 tags:"
  • For JavaScript to work on mobile devices (within MPA), you must make some changes in the Device Repository (devices.mdpr); specifically, you need to update the policies called "Support Event Handlers" (x-attributes.onevents.support) and "Script Element is supported," setting their values to "full". Both properties must have the “full” value selected, as shown in figure 1.
  • By default, the “default” option is selected, but you can override it by clicking the triangle shape --- Override, and set the value to “full.”)
  • If you are using MPTK, make sure that the modified device repository is copied.
  • If you are using the runtime environment with a Mail and Calendar Services (MCS) database, make the changes and then import the modified device repository to the database using the mcsImport command.
Figure 1. Device Repository changes made


Implementing the code


Now let's consider a JSR286 portlet with MPA support, using XDIME for MPA-related client-side development.

The following JSP scriptlet code generates the URL for the serveResources method of the portlet:

JSP Scriptlet code for making AJAX resource URL

<%
	String ajaxURL=renderResponse.createResourceURL().toString();
%>


The code in listing 1 makes the AJAX call, and "<%=ajaxURL%>" is the URL to be called for AJAX.

Listing 1. JavaScript code for making AJAX call

<script type=”text/javascript”>
function loadAjax() 
	{ 
	  	xmlhttp=GetXmlHttpObject(); 
		
	        if (xmlhttp==null) 
  			{ 
	   			alert ("Your browser does not support Ajax HTTP"); 
   				return; 
  			} 
   var url= "<%=ajaxURL%>";  //this url set in the JSP scriptlet code .
		
	   xmlhttp.onreadystatechange=getOutput; 
	   xmlhttp.open("GET",url,true); 
    	   xmlhttp.send(null); 
  
	} 


function GetXmlHttpObject() 
		{	
      	 	 if (window.XMLHttpRequest) 
   		 	{ 
			
    	 	 	 return new XMLHttpRequest(); 
   			} 
    			
			if (window.ActiveXObject) 
    			{ 
			
    	 		 return new ActiveXObject("Microsoft.XMLHTTP"); 
    			} 
 		} 

  function getOutput() 
		{ 
        	if(xmlhttp.readyState=="4" &#38;&#38; xmlhttp.status=="200")  // && is treated as &#38; in XDIME 1 .
		      {
				 		document.getElementById("ajax_address_div").innerHTML=xmlhttp.responseText; 
			return true;		
		}
		} 


The code in boldface in listing 2 has the <div> that will be refreshed by the AJAX response.

Listing 2. XDMIE code in the JSP

<pane name="postcode_btn_pane"> 
				
 				<div id="postcodebtn_div"> 
 		 		<xfaction  type="perform" class="addressbtn" onclick="\{return information('4')\}" entryPane="postcode_btn_pane"  />
 		 		</div>
 			</pane>
			
			<pane name="ajax_address_pane"> 
				<div id="ajax_address_div"></div>
			</pane>


The code in listing 3 returns the HTML response to the client side.

Listing 3. Portlet code

public  void serveResource(ResourceRequest req, ResourceResponse res)
 	throws PortletException, IOException {
	
		
 		String responsetext ="<div id='chooseAddress01' class='container actionStrip mt10 hidden chooseAddress' >"+
 		"<h4>Choose your address from the list below</h4><div>"+
 		"<select id='addressResults01' class='selectAddress' name='address'>"+
 		"<option value='Item 0'>41 Quilter Street, London E2 7BT</option><option value='Item 1'>43 Quilter Street, London E2 7BT</option>"+
 		"<option value='Item 2'>44 Quilter Street, London E2 7BT</option><option value='Item 3'>45 Quilter Street, London E2 7BT</option>"+
 		"<option value='Item 4'>46 Quilter Street, London E2 7BT</option></select></div></div>";
	
      	              res.setContentType("xdime");
 		res.setCharacterEncoding("UTF-8");
		res.getWriter().println(responsetext);
		
	}


Here are steps of the AJAX call (see figure 2 for a pictorial representation):
  1. A user enters their postcode into the textbox and clicks “Find address”, as shown in the left-hand panel of figure 2.
  2. It then calls “ajaxurl”, which ultimately calls the serveResource () method of portlet Java code and responds with HTML response text (see middle panel of figure 2).
  3. The response text from serveResource() is then refreshed on the mobile browser (see right-hand panel of figure 2).
The user can select the value by clicking the newly generated drop-down list that was refreshed by the AJAZ response.

Figure 2. Steps for the AJAX call



Note that the above-mentioned code is nothing new in terms of AJAX, nor is calling AJAX from JSR 286 portlet.

Here are some of the mobile browsers that support an AJAX xmlHTTP request object:
  • Handsets that support WebKit browsers.
  • The BlackBerry browser introduced support for the XMLHttpRequest object in BlackBerry Device Software version 4.6 (see “Support for AJAX and the XMLHttpRequest object.”)
  • iPhone, all versions.
  • Android.

Conclusion


You should now be familiar with how to use AJAX with MPA for smartphones. You can use these steps to integrate JavaScript with Mobile portlets with XDIME1.

Resources


IBM Mobile Portal Accelerator product page:
http://www-01.ibm.com/software/lotus/portal/value/mobileaccelerator/

IBM Accelerators for WebSphere Portal
http://www-01.ibm.com/software/lotus/portal/value/

developerWorks WebSphere Portal zone:
http://www.ibm.com/developerworks/websphere/zones/portal/

About the author


Amit Pareek is a Staff Software Engineer with IBM Lotus Lab Services, India Software Labs, based in Pune, India. He specializes in Enterprise portal and content management solutions, Web 2.0 technology, and Enterprise Collaboration platforms including WebSphere Portal, IBM Web Content Manager, and Lotus Quickr. You can reach him at ampareek@in.ibm.com.

Acknowledgement
The author thanks Vinoo Varghese (vvarghes@in.ibm.com) and Animesh K Sharma (animshar@in.ibm.com) for helping me learn about the MPA.


  • Edit
  • More Actions Show Menu▼


expanded Attachments (0)
collapsed Attachments (0)
Edit the article to add or modify attachments.
expanded Versions (6)
collapsed Versions (6)
Version Comparison     
VersionDateChanged by              Summary of changes
This version (6)Apr 16, 2012 12:06:13 PMLeslie Gallo  IBM contributor
5Apr 16, 2012 11:01:18 AMLeslie Gallo  IBM contributor
4Apr 12, 2012 2:36:08 PMLeslie Gallo  IBM contributor
2Apr 12, 2012 2:19:01 PMLeslie Gallo  IBM contributor
1Apr 12, 2012 2:12:48 PMMitul Kundalia  IBM contributor
1Apr 12, 2012 2:18:06 PMLeslie Gallo  IBM contributor
expanded Comments (0)
collapsed Comments (0)
Copy and paste this wiki markup to link to this article from another article in this wiki.
Go ElsewhereStay ConnectedHelpAbout
  • IBM Collaboration Solutions wikis
  • IBM developerWorks
  • IBM Software support
  • Twitter LinkIBMSocialBizUX on Twitter
  • FacebookIBMSocialBizUX on Facebook
  • ForumsLotus product forums
  • BlogsIBM Social Business UX blog
  • Community LinkIBM Collaboration Solutions
  • Wiki Help
  • Forgot user name/password
  • Wiki design feedback
  • Content feedback
  • About the wiki
  • About IBM
  • Privacy
  • Accessibility
  • IBM Terms of use
  • Wiki terms of use