![]() Operating systems: i5/OS, Linux,Windows |
The following topics describe how to migrate IBM portlets to the standard portlet API.
This topic describes some of the more common changes required to migrate an IBM portlet to a standard portlet. This does not describe all of the changes. Many migration 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 migration changes that are not covered in this topic.
import org.apache.jetspeed.portlet.*; import org.apache.jetspeed.service.*;to this:
import javax.portlet.*; import com.ibm.portal.portlet.service.*;
public class SamplePortlet extends PortletAdapter implements ActionListener{ ... }to this:
public class SamplePortlet extends GenericPortlet{ ... }
public void doView(PortletRequest request, PortletResponse response) { ... }to this:
public void doView(RenderRequest request, RenderResponse response) throws PortletException, IOException{ ... }
public void actionPerformed(ActionEvent event) throws PortletException{ ... }to this:
public void processAction(ActionRequest request, ActionResponse response) throws PortletException, IOException{ ... }
response.setContentType("text/html");
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);
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.
PortletResponse.encodeNamespace()to this:
RenderResponse.getNamespace()
// 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.
<%@ taglib uri="/WEB-INF/tld/portlet.tld" prefix="portletAPI" %>to this:
<%@ taglib uri="http://java.sun.com/portlet" prefix="portlet" %>
<portletAPI:init /> ... <% PortletData prefs = portletRequest.getData(); %>to this:
<portlet:defineObjects /> ... <% PortletPreferences prefs = renderRequest.getPreferences(); %>
<input name="<portletAPI:encodeNamespace value='name'/>" type="text" >to this:
<input name="<portlet:namespace/>name" type="text" >
<a href="<portletAPI:createURI> <portlet:URIParameter name='action' value='search'/> </portlet:createURI>" >to this:
<a href="<portlet:createActionURL> <portlet:param name='action' value='search'/> </portlet:createActionURL>" >
<portletAPI:text key="my.label" bundle="nls.myproperties"/>to this:
<fmt:setBundle basename="nls.myproperties"/> ... <fmt:message key="my.label"/>
<img src='<%= portletResponse.encodeURL("images/photo01.jpg") %>' alt="photo">to this:
<img src='<%= renderResponse.encodeURL(renderRequest.getContextPath() + "/images/photo01.jpg") %>' alt="photo">
<!DOCTYPE portlet-app-def PUBLIC "-//IBM//DTD Portlet Application 1.1//EN" "portlet_1.1.dtd ">
<portlet-app-def> .... </portlet-app-def>
<portlet-app uid="com.mycompany.samples.MyPortletApp.001c" major-version="1" minor-version="0">to this:
<portlet-app xmlns="http://java.sun.com/xml/ns/portlet/portlet-app_1_0.xsd" version="1.0" id="com.mycompany.samples.MyPortletApp.001c" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation= "http://java.sun.com/xml/ns/portlet/portlet-app_1_0.xsd http://java.sun.com/xml/ns/portlet/portlet-app_1_0.xsd">
<portlet id="com.mycompany.samples.MyPortlet.110x" href="WEB-INF/web.xml#com.mycompany.samples.MyPortlet.href110x" major-version="1" minor-version="0">to this:
<portlet id="com.mycompany.samples.MyPortlet.110x">
<servlet id="com.mycompany.samples.MyPortlet.001c"> <servlet-name>MyPortlet</servlet-name> <servlet-class>com.mycompany.samples.MyPortlet</servlet-class> </servlet> <servlet-mapping id="ServletMapping_com.mycompany.samples.MyPortlet.001c"> <servlet-name>MyPortlet</servlet-name> <url-pattern>/MyPortlet/*</url-pattern> </servlet-mapping>Add this to the portlet.xml:
<portlet-class>com.mycompany.samples.MyPortlet</portlet-class>
<cache> <expires>-1</expires> <shared>no</shared> </cache>to this:
<expiration-cache>-1</expiration-cache>
The standard portlet descriptor allows you to declare only MIME types. In some cases, two markup types use the same MIME type. For example, both HTML and cHTML use 'text/html' as the MIME type. For standard portlets, WebSphere Portal Express accepts the value of a wps.markup initialization parameter as the markup type.
Change this:<supports> <markup name="html"> <view /> <edit /> </markup> </supports>to this:
<init-param> <name>wps.markup</name> <value>html,chtml</value> </init-param> ... <supports> <mime-type>text/html</mime-type> <portlet-mode>VIEW</portlet-mode> <portlet-mode>EDIT</portlet-mode> </supports>
Be sure to place the initialization parameters before the <expiration-cache> element.
<allows> <maximized/> <minimized/> </allows>
<config-param> <param-name>Location</param-name> <param-value>Antartica</param-value> </config-param>to this:
<portlet-preferences> <preference> <name>Location</name> <value>Antartica</value> <read-only>true</read-only> </preference> </portlet-preferences>
javax.portlet.title = My Portlet Title javax.portlet.short-title = Title javax.portlet.keywords = portlets, JSR 168, portal
<resource-bundle>nls.MyPortlet</resource-bundle>
In this example, the default resource bundle MyPortlet.properties is in the /WEB-INF/nls subdirectory of the WAR file and all of the locale-specific resource bundles append the locale to the filename (for example, MyPortlet_ja.properties for Japanese).
<supported-locale>en</supported-locale> <supported-locale>de</supported-locale>
<description xml:lang="EN"> English description </description> <display-name xml:lang="EN"> English display name </display>-name> <description xml:lang="DE"> German description </description> <display-name xml:lang="DE"> German display name </display>-name>Note: The display name should be set for compatibility reasons. However, it is not currently used by WebSphere Portal Express.
The existing versions of the Struts Portlet Framework supported the IBM Portal container API, or the legacy container. This release introduces a new version of the Struts Portlet Framework that now 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 containers 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 migration from the legacy version of the Struts Portlet Framework to the Standard versions starts with migration to the jars, and TLDs shipped with the SPFStandardBlank.war file.
Here is a list of the files that should be updated in the WEB-INF/lib directory of the application:The Struts Portlet Framework defines the Request Processor that must be configured in the Struts configuration file. The controller attribute processClass needs to be migrated to the following value to be deployed on the Standard container: <controller processorClass="com.ibm.portal.struts.portlet.WpRequestProcessor"> If the Struts application is using the Struts Request processor that supports Tiles, then the Struts plugin needs to be migrated as well: <plug-in className="com.ibm.portal.struts.plugins.WpTilesPlugin">
The Struts action class is passed a HttpServletRequest object, so the application may not have a dependency on the Portal container. However, many applications use the PortletApiUtils to obtain the portlet request and interface directly with the portlet API. If this is the case then the application will have to replace the org.apache.jetspeed interfaces with the equivalent javax.portlet interfaces. The new interfaces are documented in the information center.
Note: The following example illustrates the change in which the PortletApiUtils object is obtained:The com.ibm.wps.portlets.struts.WpsStrutsPortlet class for the legacy container extended the PortletAdapter class. The Struts application using the Struts Portlet Framework may have been customized by extending the WpsStrutsPortlet class. If that is the case, then those changes will have to be migrated for the Standard container. The com.ibm.portal.struts.portlet.StrutsPortlet class for the Standard container extends the standard container's GenericPortlet.
The com.ibm.wps.portlets.struts.WpsRequestProcessor class for the legacy container may have been extended to customize the processing. The Request Processor class for the standard container is com.ibm.portal.struts.portlet.WpRequestProcessor. If the legacy interfaces were used for the customizations then these changes need to be migrated to the Standard interfaces.