In the previous step of the tutorial, Extending a Commerce Enabled Portal portlet, you familiarized yourself with the sample code that extended the portlet class, creating concrete instances of it. As a result, you now have new portlets that must be defined in the portlet.xml file and the web.xml file before they can be used in the Commerce Enabled Portal starter store.
To define the new portlet, do the following:
- From the downloaded sample code package which you copied to your Portal Toolkit machine, open the following file:
- 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.
- Snippets.xml
- Locate the portlet.xml file
- In the Project Navigator, locate the project you created when you installed and configured the development environment.
- Expand the project > WebContent > WEB-INF.
- In the Project Navigator, locate the 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.Servlet34" id="com.ibm.commerce.portal.WCSPortalNameSpace.Portlet34">
<portlet-name>Generic Catalog Portlet</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 generic catalog Commerce Enabled Portal portlet (Generic Catalog Portlet) that was created in Extending a 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.Portlet34">
<portlet-name>Generic Catalog Portlet</portlet-name>
<default-locale>en</default-locale>
<language locale="en">
<title>Generic Catalog Portlet</title>
<title-short>Generic Catalog Portlet</title-short>
<description>Generic Catalog Portlet</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>http://hostname/webapp/wcs/stores/servlet/CategoryDisplay?catalogId=catalogID&storeId=storeID&categoryId=categoryID&langId=languageID</param-value>
</config-param>
</concrete-portlet>
- Paste this code into portlet.xml directly before </concrete-portlet-app>. Note: Ensure that there are no other portlets defined in your portlet.xml with the namespace:
<concrete-portlet href="#com.ibm.commerce.portal.WCSPortalNameSpace.Portlet34"> If it is, change the Portlet34 value to another value.
- Find the following code:
<param-name>InitialRemoteURL</param-name>
<param-value>http://hostname/webapp/wcs/stores/servlet/CategoryDisplay?catalogId=catalogID&storeId=storeID&categoryId=categoryID&langId=languageID</param-value>
Change the necessary values in the InitialRemoteURL for your configuration.
This code declares the concrete instance of the generic catalog Commerce Enabled Portal portlet (Generic Catalog Portlet) that was created in Extending a Commerce Enabled Portal portlet. - Open the web.xml file:
- In the Project Navigator, locate the 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 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.Servlet34">
<servlet-name>Generic Catalog Portlet</servlet-name>
<servlet-class>com.ibm.commerce.portal.sample.ExtendedCommercePortlet</servlet-class>
<load-on-startup>0</load-on-startup>
</servlet>
- Paste this code directly before the first <servlet id> tag in web.xml. This code declares the servlet for the Generic Catalog Portlet.
- In Snippets.xml, copy the following code from Snippet 4:
<servlet-mapping id="com.ibm.commerce.portal.WCSPortalNameSpace.Servlet34Mapping">
<servlet-name>Generic Catalog Portlet</servlet-name>
<url-pattern>/genericcatalogportlet/*</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.
- Continue the tutorial by completing the steps in Creating a non WebSphere Commerce portlet application project.