Problem with Getting started with the client side programming model for portlets

The WebSPhere Portal Server 6.1 Infocenter provides this sample code for making an XMLHttpRequest method call

<%@ taglib uri="http://www.ibm.com/xmlns/prod/websphere/portal/v6.1/portlet-client-model" prefix="portlet-client-model" %>
<portlet-client-model:init>
<portlet-client-model:require module="ibm.portal.xml.*"/>
<portlet-client-model:require module="ibm.portal.portlet.*"/>
</portlet-client-model:init>
<script>
var <%=namespace%>_portletWindow = new ibm.portal.portlet.PortletWindow("<%=portletWindowID%>");
</script>
<script>

function sendXPR( /*string*/url, /*Function*/callback, /*String*/errMsg ) {
var xpr = <%=namespace%>_portletWindow.newXMLPortletRequest();
var me = this;
xpr.onreadystatechange = function () {
if ( xpr.readyState == 4 ) {
if ( xpr.status == 200 ) {
callback( xpr.responseText );
}
else {
<%=namespace%>_portletWindow.logError(“The request failed!”, errMsg );

}
}
};
xpr.open( "GET", url );
xpr.send( null );
}
</script>


I tried this to make AJAX call to my Portlet and my serveResources() method looks like this

public void serveResource(ResourceRequest request, ResourceResponse response)
throws PortletException, IOException {
System.out.println("XHRSamplePortlet.serveResource() method is called");
response.getWriter().println("This text is returned by XHRSamplePortlet.serveResource()");
}

The serveResource() method gets called on the servlet but i never get a callback. On debugging i was able to find this in portlet.js
"The XMLPortletRequest will only work for URLs which point to the portlet fragment feed."
From the code it looks like as soon as it gets response the ibm.portal.portlet.XMLPortletRequest is trying to parse it as ATOM feed and since i am returning simple text it does not like that. But it does not throw an error.

No comments: