Powered by Syntax Highlighter scripts!

Quick checklist on differences between IBM Portlets and JSR Portlets - Part 1

This article gives a quick reference for most of the differences between the IBM Portlets and JSR 168/286 portlets in Java source code.
This can also be used as a quick checklist if we frequently work on JSR portlets and have to look into a IBM portlet for troubleshooting or viceversa.


IBM Portlets implementation

JSR Portlets equivalent

Import statements to be used

import org.apache.jetspeed.portlet.*;
import org.apache.jetspeed.service.*;

import javax.portlet.*;
import com.ibm.portal.portlet.service.*;

Portlet Class inheritance

public class SampleIBMPortlet extends PortletAdapter implements ActionListener{

public class SampleJSRPortlet extends GenericPortlet{

Arguments to lifecycle methods like doView, doEdit, doHelp

public void doView(PortletRequest request, PortletResponse response) {

public void doView(RenderRequest request, RenderResponse response) throws PortletException, IOException{

Action processing

public void actionPerformed(ActionEvent event) throws PortletException{

public void processAction(ActionRequest request, ActionResponse response) throws PortletException, IOException {

Content type of Response

In IBM portlets the MIME type is set by using the JSP page directive so setting the contentType to response is not necessary.

This is required to be set in JSR portlets before including the JSP.

Dispatching to JSPs

PortletContext context = getPortletConfig().getContext();
context.include("/jsp/View.jsp", request, response);

PortletContext context = getPortletConfig().getPortletContext();
context.getRequestDispatcher("/jsp/View.jsp").include( request, response);

Accessing Portlet Preferences

PortletData portData = request.getData();
portData.setAttribute("userName", userName);

PortletPreferences prefs = request.getPreferences();

Namespace encoding

This method can be used to return unique string to be prefixed for portlet specific javascript functions.



URL generation

// Save URI for the edit page
PortletURI editPageURI = response.createURI();
// Preserve the edit page URI in the request to make it accessible by the edit page JSP
request.setAttribute("editPageURI", editPageURI.toString());

// Save URI for the edit page
PortletURL editPageURL = response.createRenderURL();
// Preserve the edit page URI in the request to make it accessible by the edit JSP
request.setAttribute("editPageURL", editPageURL.toString());

No comments: