XMLPortletRequest in Portlet Container 2.1

XMLPortletRequest is a wrapper over XMLHttpRequest and shares the same syntax and semantics with XMLHttpRequest.

If a portlet wants to update its UI asynchronously through resource URL, it would simply use XMLPortletRequest instead of the XMLHttpRequest.


Here is an example on how to use XMLPortletRequest.

<script type="text/javascript" 
        src="<%=renderRequest.getContextPath()%>/js/XMLPortletRequest.js">
</script>
<script>
    var portletRequest = new XMLPortletRequest("<portlet:namespace/>");
    portletRequest.onreadystatechange = function() {.....}
    portletRequest.open("POST", "<portlet:resourceURL escapeXml='false' />");
    portletReq.send("foo=" + bar);
</script>

Check the XPRInvoiceAjaxPortlet sample(sources and binary) that showcases the usage of XMLPortletRequest. Using XMLPortletRequest drastically reduces the amount of code. Compare the view jsp page of InvoiceAjaxPortlet that does not use XMLPortletRequest with view jsp page of XPRInvoiceAjaxPortlet that uses XMLPortletRequest.

This feature has been added in Portlet Container 2.1. This is available in OpenPortal Portlet Container 2.1, Sun GlassFish Web Space Server 10.0 and Liferay version 5.2 and higher.

Comments:

XMLPortletRequest makes the code much more concise and readable. It's a must try for everyone who indend to develop JSR-286 portlets with AJAX.

Posted by guest on May 16, 2011 at 07:37 PM IST #

Post a Comment:
  • HTML Syntax: NOT allowed
About

Deepak Gothe

Search

Categories
Archives
« April 2014
SunMonTueWedThuFriSat
  
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
   
       
Today