Tutorials > Management Center > Add new search conditions in the advanced search of the Catalogs tool

< Previous | Next >


Extend the controller JSP file to transfer extended search parameters

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, extend the controller JSP file to support these new search terms from the extAllCatalogEntriesAdvancedSearchContent class as parameters.

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 performing the search. The expressionBuilder parameter 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.

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:

  1. Locate the extension folder or create an extension folder in which to store the customized JSP files. For example, WebContent/jsp/mycompany/component.

  2. Locate the IBM supplied controller JSP file in the restricted directory.

  3. Create a new JSP file that is only used to handle requests that contain the custom parameters.

  4. Create a new delegating controller JSP file that determines if the request contains the custom parameters. If the request contains your custom parameters, it should forward to the custom controller JSP file. If the request does not contain the custom parameters, it should forward to the IBM supplied JSP controller file.

  5. Override the IBM Struts action to use the new delegating controller JSP file instead.

For the scenario in this tutorial, follow these steps to extend the controller JSP file.


Procedure

  1. Determine which controller JSP file is used by the Catalog Entry Advanced Search

    1. Complete one of the following steps:

    2. 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.

    3. Navigate to LOBTools > WebContent > WEB-INF and double-click one of the following files to open it in the default editor:

      • struts-ibm-tools.xml

      • struts-ibm-catalog.xml

      Do not change this XML file since it might be replaced in a fix pack.

    4. 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.

  2. Create the extension controller JSP file

    1. Navigate to LOBTools > WebContent > jsp.

    2. To create the JSP extension folder, right-click jsp and select New > Folder.

    3. In the Folder name field, type mycompany, click Next, and then click Finish.

    4. In the mycompany directory create a folder called catalog.

    5. To create the extension controller JSP file, right-click the catalog folder and select New > File.

    6. In the File name field, type FindAllCatalogEntries-WithWarrentyCriteria.jsp, and then click Finish.

    7. 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" />
      

      The JSP file uses the new expression Builder, findMyCompanyAdvancedSearch, to get data that will be defined later in the Create a new expression builder to override a default expression builder step.

  3. Create the delegating controller JSP file

    1. Navigate to LOBTools > WebContent > jsp > mycompany > catalog.

    2. Right-click the catalog folder and select New > File.

    3. In the File name field, type FindAllCatalogEntries.jsp, and then click Finish.

    4. 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:

      1. If either the Warterm or Wartype search condition is selected, the delegating controller JSP file forwards to the extension controller JSP file.

      2. If neither the Warterm nor Wartype search condition is selected in the Advanced Search dialog, the delegating controller JSP file forwards to the IBM supplied controller JSP file, FindAllCatalogEntries.jsp. This file is located in the LOBTools/WebContent/jsp/commerce/catalog/restricted directory.

  4. Extend the Struts configuration to point the action to the extended JSP file

    1. 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.

    2. In the struts-extension.xml file, add the following line to the action-mappings section:

      <action path="/FindCatalogEntries-All" forward="/jsp/mycompany/catalog/FindAllCatalogEntries.jsp" />
      

      The definition for /FindCatalogEntries-All overrides the definition in one of the following default Struts files:

      • struts-ibm-tools.xml

      • struts-ibm-catalog.xml

    3. Click Save.

< Previous | Next >


+

Search Tips   |   Advanced Search