Each wcfSearchDefinition has an associated
wcfSearchService. This service is implemented as a controller JSP
file that takes the search terms as parameters. When you add new search
terms, you must extend the controller JSP file to support these new
search terms from the extAllCatalogEntriesAdvancedSearchContent class
as parameters.
About this task
The search service is preceded by the wcf:getData
tag in the controller JSP file. The expressionBuilder
parameter defines the query template to run when it performs the search.
The expressionBuilder parameter that is defined
in the get-data-config.xml file cannot read the
parameter values in the Advanced Search dialog. The controller JSP
file transfers the search parameters between the Advanced Search dialog
(extAllCatalogEntriesAdvancedSearchContent) and the get-data-config.xml file.
Note: To
facilitate future migration and maintenance, all JSP files in the
LOBTools project are placed into a restricted folder and cannot be
directly modified during customization. Use the following method to
extend JSP files:
- Locate the extension folder or create an extension folder in
which to store the customized JSP files. For example, WebContent/jsp/mycompany/ component.
- Locate the IBM supplied controller JSP file in the restricted
directory.
- Create a JSP file that is only used to handle requests that contain
your custom parameters.
- Create a new delegating controller JSP file that determines whether
the request contains your custom parameters. If the request contains
your custom parameters, it forwards to your custom controller JSP
file. If the request does not contain your custom parameters, it forwards
to the IBM supplied JSP controller file.
- Override the IBM Struts action to use your new delegating controller
JSP file instead.
For the scenario in this tutorial, follow these
steps to extend the controller JSP file.
Procedure
- Determine which controller JSP file is used by the Catalog
Entry Advanced Search
- Complete one of the following steps:
- Complete one of the following steps:
- In the wcfSearchService
section, specify the value of the URL property:
url="/cmc/FindCatalogEntries-All"
.
The URL property means that the Struts action is invoked by the search
service.
- In the SearchService
section, note the value of the URL attribute:
url="/cmc/FindCatalogEntries-All"
. This
is the Struts action that is invoked by the search service.
- Navigate to and double-click one of the following files to open
it in the default editor:
- Locate the action definition in the action-mappings
section by searching for
FindCatalogEntries-All
.
The search result is:
<!-- Catalog Tool Search Definitions -->
<!-- ========= -->
<action path="/FindSKUs" forward="/jsp/commerce/catalog/restricted/FindSKUs.jsp" />
<action path="/FindKits" forward="/jsp/commerce/catalog/restricted/FindKits.jsp" />
<action path="/FindDynamicKits" forward="/jsp/commerce/catalog/restricted/FindDynamicKits.jsp" />
<action path="/FindBundles" forward="/jsp/commerce/catalog/restricted/FindBundles.jsp" />
<action path="/FindProducts" forward="/jsp/commerce/catalog/restricted/FindProducts.jsp" />
<action path="/FindSalesCategories" forward="/jsp/commerce/catalog/restricted/FindSalesCategories.jsp" />
<action path="/FindCatalogEntries-ExceptSKUs" forward="/jsp/commerce/catalog/restricted/FindAllCatalogEntriesExceptSKUs.jsp" />
<action path="/FindCategories-All" forward="/jsp/commerce/catalog/restricted/FindAllCategories.jsp" />
<action path="/FindCatalogEntries-All" forward="/jsp/commerce/catalog/restricted/FindAllCatalogEntries.jsp" />
<action path="/FindCatalogs" forward="/jsp/commerce/catalog/restricted/FindCatalogs.jsp" />
- The search result for
FindCatalogEntries-All
indicates
that the controller JSP file to be extended is /jsp/commerce/catalog/restricted/FindAllCatalogEntries.jsp.
- Create the extension controller JSP file.
- Navigate to .
- To create the JSP extension folder, right-click jsp
and select .
- In the Folder name field,
type mycompany, click Next,
and then click Finish.
- In the mycompany directory, create
a folder that is called catalog.
- To create the extension controller JSP file, right-click
the catalog folder and select .
- In the File name field, type FindAllCatalogEntries-WithWarrentyCriteria.jsp,
and then click Finish.
- Copy the following code into the FindAllCatalogEntries-WithWarrentyCriteria.jsp file:
<?xml version="1.0" encoding="UTF-8"?>
<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c"%>
<%@ taglib uri="http://commerce.ibm.com/foundation" prefix="wcf"%>
<%-- Decide which expression builder to call based on the input --%>
<wcf:getData
type="com.ibm.commerce.catalog.facade.datatypes.CatalogEntryType[]"
var="catentries" expressionBuilder="findMyCompanyAdvancedSearch"
varShowVerb="showVerb"
recordSetStartNumber="${param.recordSetStartNumber}"
recordSetReferenceId="${param.recordSetReferenceId}"
maxItems="${param.maxItems}">
<wcf:contextData name="storeId" data="${param.storeId}" />
<wcf:contextData name="catalogId" data="${catalog}" />
<wcf:param name="shortDescription" value="" />
<wcf:param name="mfPartNumber" value="${param.mfPartNumber}" />
<wcf:param name="mfName" value="${param.manufacturer}" />
<wcf:param name="groupIdentifier" value="${param.parentCategory}" />
<c:if test="${param.wartermSelection != 'null'}">
<c:set var="warterm" value="${param.wartermSelection}" />
</c:if>
<wcf:param name="wartermSelection" value="${warterm}" />
<c:if test="${param.wartypeSelection != 'null'}">
<c:set var="wartype" value="${param.wartypeSelection}" />
</c:if>
<wcf:param name="wartypeSelection" value="${wartype}" />>
<wcf:param name="partNumber" value="${catentryCode}" />
<wcf:param name="name" value="${catentryName}" />
<c:set var="productExp" value="ProductBean" />
<c:set var="bundleExp" value="BundleBean" />
<c:set var="kitExp" value="PackageBean" />
<c:set var="dynamicKitExp" value="DynamicKitBean" />
<c:set var="SKUExp" value="ItemBean" />
<c:if test="${(empty param.published)}">
<wcf:param name="published" value="" />
</c:if>
<c:if test="${param.published == '1'}">
<wcf:param name="published" value="1" />
</c:if>
<c:if test="${param.published == '2'}">
<wcf:param name="published" value="0" />
</c:if>
<c:if test="${param.published == '3'}">
<wcf:param name="published" value="" />
</c:if>
<c:if test="${(empty param.catentryTypes)}">
<wcf:param name="catEntryTypes"
value="${productExp},${bundleExp},${kitExp},${dynamicKitExp},${SKUExp}" />
</c:if>
<c:if test="${param.catentryTypes == '1'}">
<wcf:param name="catEntryTypes"
value="${productExp},${bundleExp},${kitExp},${dynamicKitExp}" />
</c:if>
<c:if test="${param.catentryTypes == '2'}">
<c:set var="typeParam" value="" />
<c:if test="${param.typeProducts == 'true'}">
<c:if test="${typeParam != ''}">
<c:set var="typeParam" value="${typeParam}," />
</c:if>
<c:set var="typeParam" value="${typeParam}${productExp}" />
</c:if>
<c:if test="${param.typeBundles == 'true'}">
<c:if test="${typeParam != ''}">
<c:set var="typeParam" value="${typeParam}," />
</c:if>
<c:set var="typeParam" value="${typeParam}${bundleExp}" />
</c:if>
<c:if test="${param.typeKits == 'true'}">
<c:if test="${typeParam != ''}">
<c:set var="typeParam" value="${typeParam}," />
</c:if>
<c:set var="typeParam" value="${typeParam}${kitExp},${dynamicKitExp}" />
</c:if>
<c:if test="${param.typeSKUs == 'true'}">
<c:if test="${typeParam != ''}">
<c:set var="typeParam" value="${typeParam}," />
</c:if>
<c:set var="typeParam" value="${typeParam}${SKUExp}" />
</c:if>
<wcf:param name="catEntryTypes" value="${typeParam}" />
</c:if>
</wcf:getData>
<jsp:directive.include
file="../../commerce/catalog/restricted/serialize/SerializeCatalogEntries.jspf" />
- Create the delegating controller JSP file
- Navigate to .
- Right-click the catalog folder and select .
- In the File name field, type FindAllCatalogEntries.jsp,
and then click Finish.
- Copy the following code into the FindAllCatalogEntries.jsp file:
<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c"%>
<c:choose>
<c:when
test="${! ((empty param.wartermSelection || param.wartermSelection=='null')
&& (empty param.wartypeSelection || param.wartypeSelection=='null')) }">
<jsp:forward page="FindAllCatalogEntries-WithWarrentyCriteria.jsp" />
</c:when>
<c:otherwise>
<jsp:forward
page="../../commerce/catalog/restricted/FindAllCatalogEntries.jsp" />
</c:otherwise>
</c:choose>
- This code shows how the delegating controller JSP file
decides which controller JSP file to delegate to:
- If either the Warterm or Wartype search condition is selected,
the delegating controller JSP file forwards to the extension controller
JSP file.
- If the Warterm or Wartype search condition is not selected in
the Advanced Search dialog, the delegating controller JSP file forwards
to the IBM supplied controller JSP file, FindAllCatalogEntries.jsp.
This file is in the LOBTools/WebContent/jsp/commerce/catalog/restricted
directory.
- Extend the Struts configuration to point the action to
the extended JSP file
- The Struts configuration extension file is already
provided in \LOBTools\WebContent\WEB-INF\struts-extension.xml. Navigate
to the \LOBTools\WebContent\WEB-INF directory
and double-click the struts-extension.xml file
to open it in the default editor.
- In the struts-extension.xml file,
add the following line to the action-mappings section:
- Click Save.