Theme and Skin in seperate .ear

Starting from WPS 6.1 you can create a Theme or Skin in separate .war file and install it on portal. You dont have to modify the wps.war any more. I followed the Infocenter Instructions for Creating a new theme and skin to create MyTheme.war and MySkin.war along with my own version of DeployTheme.xml that i can use to deploy both MyTheme.war and MySkin.war. Attaching those files below



First install MyTheme.war and MySkin.war as enterprise applications from the WAS Admin Console and then execute the DeployTheme.xml as xmlaccess script.

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.

Sample XHR request to portelt

This is the sample of how you can send the XHR request to the portlet and call its serveResource() method. Click here to download sample portlet


The sample in Infocenter about _portletWindow.newXMLPortletRequest never works. Even though i can see the XHR request my callback does not get called.




<%@page language="java" contentType="text/html; charset=ISO-8859-1"
pageEncoding="ISO-8859-1" session="false"%>
<%@ taglib uri="http://java.sun.com/portlet_2_0" prefix="portlet"%>
<%@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>
<portlet:defineObjects />
<div id="test">initial text</div>
<script language="JavaScript">
function handleOnClick(){
console.log("Exiting handleOnClick");
dojo.xhrGet({
url: '<portlet:resourceURL/>',
load: function(data){
console.log("load is called");
dojo.byId("test").innerHTML = data;
},
error: function(data){
console.log("error is called")
}
});

console.log("Exiting handleOnClick");
}
</script>
<p><input type="submit" name="Test" value="Test" onclick="handleOnClick()"></p>

Sample code for working with User Profiles on the clent side

<%@page language="java" contentType="text/html; charset=ISO-8859-1"
pageEncoding="ISO-8859-1" session="false"%><%@taglib
uri="http://java.sun.com/portlet" prefix="portlet"%><%@taglib
uri="http://www.ibm.com/xmlns/prod/websphere/portal/v6.1/portlet-client-model"
prefix="portlet-client-model"%><%@taglib
uri="http://java.sun.com/portlet" prefix="portletx"%><portlet-client-model:init>
<portlet-client-model:require module="ibm.portal.xml.*" />
<portlet-client-model:require module="ibm.portal.portlet.*" />
</portlet-client-model:init>
<portlet:defineObjects />
<p>User Profile Sample</p>
<script>
_portletWindow = new ibm.portal.portlet.PortletWindow("<%=portletWindowID%>");
function handleUserProfile(portletWindow, status, userProfile){
console.log("Inside handleUserProfile");
console.log(userProfile);
if (status==ibm.portal.portlet.PortletWindow.STATUS_OK) {
// This is sample of how to get attributes from User Profile
console.log("Preferences.getValue()\n"+ userProfile.getAttribute("uid"));
//Follow these two steps to set attribute
userProfile.setAttribute("displayName","Sunil Patil");
_portletWindow.setUserProfile(userProfile);
}
else {
console.log("error loading feed");
}
}
_portletWindow.getUserProfile(handleUserProfile);
</script>

You can download this sample from here

JavaScript Butification

If you want to uncompress the JavaScript then you can use JavaScript Beautifier