Converting IBM portlets

You can convert basic IBM portlets as well as IBM portlets that use the Struts Portlet Framework to the standard portlet API.


Converting basic IBM portlets to the standard

This topic describes some of the more common changes (but not all) that are required to convert an IBM portlet to a standard portlet. Many conversion tasks depend on the amount of complexity in the portlet code. You will have to become familiar with the Java Portlet Specification to determine any remaining changes that are not covered in this topic.

Change Java source

  1. Change import statements to use the standard packages.

      Change this:

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

      to this:

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

  2. Change class inheritance to use GenericPortlet. Notice that the ActionListener is not implemented.

      Change this:

          public class SamplePortlet extends PortletAdapter implements ActionListener{  
          ...
          }

      to this:

          public class SamplePortlet extends GenericPortlet{
          ...
          }

  3. Change objects used for all render methods. In the standard portlet API, the PortletRequest and PortletResponse define common functionality for the RenderRequest and RenderResponse subclasses. These subclasses are the arguments for all implementations of the render() method, including doView(), doEdit(), and doHelp().

      Change this:

        public void doView(PortletRequest request, PortletResponse response) {  
           ...
        }
          

      to this:

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

  4. Change the actionPerformed() method. In the standard portlet API, this method is replaced by the processAction() method, which does not require the portlet to implement a listener. The processAction() methods accepts the ActionRequest and ActionResponse as arguments, which extend the PortletRequest and PortletResponse.

      Change this:

          public void actionPerformed(ActionEvent event) throws PortletException{  
          ...
          }
          

      to this:

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

  5. Change how the response content type is set. In the standard portlet API, the MIME type of the output returned in the response must be set before including the JSP. IBM portlets declare the MIME type using the contentType attribute of JSP's page directive. Therefore, this change makes the contentType setting in the JSP unnecessary.

      Add this before including the JSP:

      response.setContentType("text/html");
      
      
      

  6. Change JSP includes. In the standard portlet API, JSPs are included by a request dispatcher's include() method. In the portlets' render method, set the MIME type of the output before returning it in the response.

      Change this:

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

      to this:

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

  7. Change classes where user data is stored. In the standard portlet API, user data is stored in a PortletPreferences object, rather than the PortletData object that is available using the IBM portlet API. Notice the different getter methods used with the request object and setter methods used for the data object.

      Change this:

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

      to this:

              PortletPreferences prefs = request.getPreferences();
              prefs.setValue("userName",request.getParameter("username"));  
              prefs.store();
      
      
      

      Some preferences are read-only and can be modified only by an administrator. See Change configuration parameters to preferences for more information.

  8. Change the method used for namespace encoding. For example, if the portlet uses encodeNamespace() to return a unique string to be prefixed to a JavaScript variable name within the content generated by the portlet, the portlet should now use getNamespace().

      Change this:

              PortletResponse.encodeNamespace()   
          

      to this:

              RenderResponse.getNamespace()
      
      
      

  9. Change how portlet URLs are generated. For example, a portlet's doEdit() method might save the URI to the edit mode to pass to the JSP. The portlet must instantiate a PortletURL object using the createRenderURL() method.

      Change this:

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

      to this:

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

      The standard portlet API does not have an equivalent method for createReturnURI(). If the URL is intended to call the portlets' action method, however, the portlet should use the createActionURL() method.

Change JSP source

  1. Change the tag library to use the standard tag library.

      Change this:

          <%@ taglib uri="/WEB-INF/tld/portlet.tld" prefix="portletAPI" %>
      
      
      

      to this:

          <%@ taglib uri="http://java.sun.com/portlet" prefix="portlet" %>  
      
      
      

  2. Change references to API objects. In the standard portlet API, the <portlet:defineObjects /> JSP tag makes the RenderRequest, RenderResponse, and PortletConfig objects available to JSP files. After making this change, all references in the JSP to the PortletRequest and PortletResponse should be changed to the corresponding RenderRequest and RenderResponse.

      Change this:

          <portletAPI:init /> 
          ...
          <%
          PortletData prefs = portletRequest.getData();
          %>    
      
      
      

      to this:

         <portlet:defineObjects /> 
         ...
         <%
         PortletPreferences prefs = renderRequest.getPreferences();
         %>    
      
      
      

  3. Change JSP tags used for namespace encoding. For example, if the portlet uses <portletAPI:encodeNamespace/> to uniquely qualify the name of a text input field, this tag must be changed as follows.

      Change this:

         <input name="<portletAPI:encodeNamespace value='name'/>"  type="text" >   
      
      
      

      to this:

         <input name="<portlet:namespace/>name"  type="text" >   
      
      
      

  4. Change how portlet URLs are generated. If the portlet JSP creates a URL to itself, it should specify which method gets control using the <portlet:actionURL/> or <portlet:renderURL/> tags. Any parameters passed on the URL are specified using the <portlet:param/> tag.

      Change this:

         <a href="<portletAPI:createURI>
                     <portlet:URIParameter name='action' value='search'/>   
                  </portlet:createURI>" >

      to this:

         <a href="<portlet:actionURL>
                     <portlet:param name='action' value='search'/>
                  </portlet:actionURL>" >  

  5. Change resource bundles. The <portletAPI:text/> tag of the IBM Portlet API has been deprecated and should be replaced in all portlets by the JSTL equivalent. See Use JSTL in portlet JSPs for more information.

      Change this:

          <portletAPI:text key="my.label" bundle="nls.myproperties"/>  
      
      
      

      to this:

          <fmt:setBundle basename="nls.myproperties"/>
          ...
          <fmt:message key="my.label"/>
      
      
      

  6. Change how resources are invoked from the JSP. For example, if the JSP displays an image, it should use the encodeURL() method of the appropriate response object and, in addition, add the context path of the portlet from the request.

      Change this:

        <img src='<%= portletResponse.encodeURL("images/photo01.jpg") %>' 
          alt="photo">   
      
      
      

      to this:

      <img src='<%= renderResponse.encodeURL(renderRequest.getContextPath() + 
                    "/images/photo01.jpg") %>' alt="photo">
      
      
      

Change the portlet deployment descriptor


Converting IBM portlets that use the Struts Portlet Framework

The existing versions of the Struts Portlet Framework supported the IBM Portal container API, or the legacy container. This release uses a newer version of the Struts Portlet Framework that supports the standard portlet container. This release will continue to ship a version to support the legacy container and a new version for the Standard container. The Struts Portlet Framework is still shipped as example war files that can be used to build the Struts application. The war files for each container can be distinguished by the name. The SPFLegacy examples support the legacy container, and the SPFStandard examples support the standard container. The SPFLegacyBlank.war is the starting point for Struts applications for the Legacy container, and the SPFStandardBlank is the starting point for the Struts applications for the Standard container.
The Struts Portlet Framework for the Legacy Container


Files common to both the standard and IBM portlet containers


Conversion to the Standard Version of the Struts Portlet Framework from previous versions of the Struts Portlet Framework


Web Deployment Descriptor


Portlet Deployment Descriptor


Struts Configuration File


Struts Action


StrutsPortlet


Request processor


Parent

IBM Portlet API

 


+

Search Tips   |   Advanced Search