Portlet aggregation

The WebSphere Application server does not provide a powerful aggregation engine like that of WebSphere Portal or it does not provide capability to create look and feel of the portal using Theme and Skin. Instead it provides a tag library that you can use to invoke portlet and put its output on a page.

I wanted to try that so i created a simple HelloWorldPortlet.war file it has 2 portlets HelloWorldPortlet and HelloWorldPortlet2. Both those portlets simply write there name in the response.

In order to aggregate the output of both these portlets on the page first i had to create a portal.jsp like this


<%@page language="java" contentType="text/html; charset=ISO-8859-1" pageEncoding="ISO-8859-1" %>
<%@ taglib uri="http://ibm.com/portlet/aggregation" prefix="portlet" %>
<%@ page isELIgnored ="false"%>
<portlet:init portletURLPrefix="/helloworldportlet/portal/">
<table border='1' bordercolor='black'>
<tr>
<td><portlet:insert url="helloworldportlet/HelloWorldPortlet" windowId="helloworld" titleVar="Hello World Portlet"/></td>
</tr>
<tr>
<td><portlet:insert url="helloworldportlet/HelloWorldPortlet2" windowId="helloworld1" titleVar="Hello World Portlet 2"/></td>
</tr>
</table>

</portlet:init>


In order for aggregation first you need a portal context that you can initialize using init tag it takes context as parameter that should be the context of the servlet or JSP that is generating the portal page. In this case portal.jsp page is mapped to /helloworldportlet/portal so that is the context.

Next you need a insert tag pointing to portlet, that is the place where output generated by portlet will be placed. In my case i have two portlets that i want to aggregate on the page so i have 2 portlet:insert tags pointing to them

Then i had to change my web.xml file to declare context for portal.jsp like this.


<?xml version="1.0" encoding="UTF-8"?>
<web-app id="WebApp_ID" version="2.4" xmlns="http://java.sun.com/xml/ns/j2ee" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://java.sun.com/xml/ns/j2ee http://java.sun.com/xml/ns/j2ee/web-app_2_4.xsd">
<display-name>HelloWorldPortlet</display-name>
<servlet>
<servlet-name>SamplePortal</servlet-name>
<jsp-file>portal.jsp</jsp-file>
</servlet>
<servlet-mapping>
<servlet-name>SamplePortal</servlet-name>
<url-pattern>/portal/*</url-pattern>
</servlet-mapping>
<welcome-file-list>
<welcome-file>portal.jsp</welcome-file>
</welcome-file-list>
</web-app>


I deployed my HelloWorldPOrtlet.war file on the WAS server and then tried accessing it i can see this output.



As you can see it does not provide facility to display modes supported by portlet or title of the portlet or ability to switch mode. If you want those things then you will have to use Portlet MBean and manually create skin for each of the portlet

1 comment:

Anonymous said...

how can we have portlet insert url to be create dynamically using a variable ?