Wednesday, August 12, 2009

How to write Alphablox JSR168 Portlet in WebSphere Environment

Alphablox is used to present consolidated information and analytical capabilities in rich diagrams and reports. Here I am going to show you how to write a simple Alphalox JSR168 Portlet by presenting an example.

Working Environment

· Developement Tool: RAD 6.0.1.1 + Interim Fix 003 // Alphablox Toolkit is not supported in RAD7.0 currently

· WebSphere Application Server v 6.0.2.11

· WebSphere Portal Server v5.1.0.3

· Alphablox V8.4.0 is installed on top of WPS V5.1.0.3

Alphalbox Portlet (JSR168) Sample

This sample uses the default data source which is automatically installed with Alphablox.

Lines marked with red are important points of writting an JSR168 Alphalbox Portlet.

<%@ page contentType="text/html" import="java.util.*,java.io.*"%>

<%@ taglib uri="bloxtld" prefix="blox"%>

<%@ taglib uri="http://java.sun.com/portlet" prefix="portlet" %> //This line indicates we are using JSR168 API specification

<%
String bloxName = renderResponse.getNamespace() + "chartBlox0";

%>

<head>

<blox:header />

head>

<blox:chart id="chartBlox" bloxName="<%= bloxName %>">

<blox:data dataSourceName="Canned" />

blox:chart>

Some Words about Alphablox and its Portlet

You may see a lot of Alphablox advantages on internet but not its shortcoming, here, based on my limited experience, I list some inconvenience of using it and hope they will be noticed and enhanced in the future.

1. Alphalbox support standard J2EE model, but it is not compatible with SOA architecture.

As I experienced, Alphablox does not provide any interfaces to support SOA, which means, it is impossible in Alphablox to invoke service which returns data sets in XML format.

There are two ways to access datasource in Alphablox (please refer to my next blog: Tow different ways of accessing Datasource in Alphablox for more information)
a). work directly with sql statement
b). work with java.sql.ResultSet

2. It is impossible for an Alphablox Portlet to be a source portlet

For instance, this is a report alphalbox portlet. You want to get the detail information in a target portlet of a product that you selected in source, however, this scenario can not be realized.

However, it is possible for a Alphablox Portlet to be a target portlet. In this case, there is one thing you need to pay attention. Normally, you want the target Alphablox Portlet will change itself according to the different selection on the source portlet, if so, in the above blox code, the bloxName attribute should be different each time so that Alphablox Server knows this is a new one, otherwise, the blox will remain unchanged. To achieve this, one possible way is to use random value.

Random r = new Random();
int i = r.nextInt();
if (i<0) i="i*(-1);" style="font-weight: bold;">

String bloxName = renderResponse.getNamespace() + "standingRankingSeasonBox_"+i;

3. Unfriendly JSP Page

As we have seen on the above sample code, all Alphablox code should be written on the jsp, sometimes even the business logic which increased the complication of jsp page.