In order to create a new Commerce Enabled Portal portlet that is based on an existing portlet, you need only to define it in the portlet.xml file and the web.xml before it can be used in the Commerce Enabled Portal starter store.
In this step you will create the Product Information Display portlet.
To define the new Product Information Display portlet, do the following:
- From the downloaded sample code package which you copied to your WebSphere Portal Development machine, open the following file:
- Samples\Sample3\Snippets.xml
Snippets.xml contains code samples that you can copy and paste to the portlet.xml and web.xml files to define the new portlet.
- Samples\Sample3\Snippets.xml
- Locate the portlet.xml file
- In the Project Navigator, locate the portlet project you created when you installed and configured the development environment.
- Expand the project > WebContent > WEB-INF.
- In the Project Navigator, locate the portlet project you created when you installed and configured the development environment.
- Open portlet.xml. The file displays in the main window. Select the Source view.
- Find the following code:
</portlet-app>
- Find the following code:
- In Snippets.xml, copy the following code from Snippet 1:
<portlet href="WEB-INF/web.xml#com.ibm.commerce.portal.WCSPortalNameSpace.Servlet35" id="com.ibm.commerce.portal.WCSPortalNameSpace.Portlet35">
<portlet-name>Product Info Display</portlet-name>
<cache>
<expires>-1</expires>
<shared>no</shared>
</cache>
<allows>
<maximized />
<minimized />
</allows>
<supports>
<markup name="html">
<view />
</markup>
</supports>
</portlet>
Paste this code into portlet.xml directly before </portlet-app>. This code declares the Product Info Display Commerce Enabled Portal portlet.
- In portlet.xml, find the following code:
</concrete-portlet-app>
- In Snippets.xml, copy the following code from Snippet 2:
<concrete-portlet href="#com.ibm.commerce.portal.WCSPortalNameSpace.Portlet35">
<portlet-name>Product Info Display</portlet-name>
<default-locale>en</default-locale>
<language locale="en">
<title>Product Info Display</title>
<title-short>Product Info Display</title-short>
<description>Product Info Display</description>
<keywords>WCS</keywords>
</language>
<config-param>
<param-name>ApplicationNamespace</param-name>
<param-value>com.ibm.commerce.portal.WCSPortalNameSpace</param-value>
</config-param>
<config-param>
<param-name>SSOEnabled</param-name>
<param-value>true</param-value>
</config-param>
<config-param>
<param-name>RefreshPriority</param-name>
<param-value>-1</param-value>
</config-param>
<config-param>
<param-name>com.ibm.wps.portlet.action.redirect</param-name>
<param-value>true</param-value>
</config-param>
<config-param>
<param-name>InitialRemoteURL</param-name>
<param-value>https://hostname/webapp/wcs/stores/servlet/ProductDisplay?catalogId=catalogID&productId=productID&storeId=storeId&langId=languageID&productInfo=true&initUrl=true</param-value>
</config-param> </concrete-portlet>
Paste this code into portlet.xml directly before </concrete-portlet-app>. Change the necessary values in the InitialRemoteURL for your configuration. This code declares the concrete instance of the Product Info Display Commerce Enabled Portal portlet. Save the modified portlet.xml file.
- Open the web.xml file:
- In the Project Navigator, locate the portlet project you created when you installed and configured the development environment.
- Expand the project > WebContent > WEB-INF. Open web.xml.
- In the Project Navigator, locate the portlet project you created when you installed and configured the development environment.
- In Snippets.xml, copy the following code from Snippet 3:
<servlet id="com.ibm.commerce.portal.WCSPortalNameSpace.Servlet35">
<servlet-name>Product Info Display</servlet-name>
<servlet-class>com.ibm.commerce.portal.wpsportlets.DynamicWCSServletInvokerPortlet</servlet-class>
<load-on-startup>0</load-on-startup>
</servlet>
- Paste this code directly before the first <servlet-mapping id> tag in web.xml. This code declares the servlet for the Product Info Display portlet.
- In Snippets.xml, copy the following code from Snippet 4:
<servlet-mapping id="com.ibm.commerce.portal.WCSPortalNameSpace.Servlet35Mapping">
<servlet-name>Product Info Display</servlet-name>
<url-pattern>/productinfodisplay/*</url-pattern>
</servlet-mapping>
- In web.xml, find </web-app>. Paste the code from Snippet 4 directly before this tag. The code defines the mapping between the servlet and the portlet.
- In web.xml find the following code:
<servlet id="com.ibm.commerce.portal.WCSPortalNameSpace.Servlet3">
<servlet-name>Shopping Cart</servlet-name>
<servlet-class>com.ibm.commerce.portal.wpsportlets.WCSServletInvokerPortlet</servlet-class>
<load-on-startup>0</load-on-startup>
</servlet>
Add the word Dynamic to the following line as illustrated:
<servlet-class>com.ibm.commerce.portal.wpsportlets.DynamicWCSServletInvokerPortlet</servlet-class>
- Save your changes.