Tutorials > Sales Center > Add a new search option in the IBM Sales Center

< Previous | Next >


Write code to search for the new search option

This section refers to the code needed for searching for the new search option.

The ShowElectronicCatalog class contains the code that handles searching for and displaying products. The TelesalesRegistry.xml file maps actions, or nouns and verbs, to Java classes. In the TelesalesRegistry.xml file, the following lines show that when the client gets information about the electronic catalog, the class com.ibm.commerce.telesales.messaging.bodreply.ShowElectronicCatalog runs: <Noun name="ElectronicCatalog"> <Verb name="Get"> <ClassName>com.ibm.commerce.telesales.messaging.bodreply.ShowElectronicCatalog</ClassName> </Verb> </Noun>

The ShowElectronicCatalog class' initialization method, initializeCatalogEntriesSearch, populates an AdvancedCatEntrySearchListDataBean data bean based on the search criteria entered by the user. In this step we will extend the ShowElectronicCatalog class to load manufacturer part number information into the data bean if this information is specified by the user.

In the previous steps of this tutorial, you added code to a plug-in that runs in the Sales Center environment. This code in this step is created in WebSphere Commerce Developer and runs on the WebSphere Commerce Server.

To extend the ShowElectronicCatalog class:


Procedure

  1. Open WebSphere Commerce Developer.

  2. In the Java EE perspective, In the Enterprise Explorer view, navigate to Other Projects > WebSphereCommerceServerExtensionsLogic > src.

  3. Right-click the src project and select New > Package.

  4. In the Name field, enter com.mynewextensions.mfpartnumber and click Finish.

  5. Right-click the com.mynewextensions.mfpartnumber package and select New > Class.

  6. In the Name field, enter ExtendedShowElectronicCatalog.

  7. Next to the Superclass field, click Browse.

  8. In the Choose a type field, enter ShowElectronicCatalog and click OK.

  9. Click Finish.

  10. Copy and paste the following code into the new class, in between the { and } characters:

    /*
    * This method first calls the superclass'
    initializeCatalogEntriesSearch
    * method. If
    <code> aSearchCriteria
    </code> contains a
    Manufacturer Part
    * Number then the search criteria, case sensitive and search type
    values
    * are set in the
    <code> abnCatalogEntriesSearch
    </code>
    data bean.
    * 
    * @see
    com.ibm.commerce.telesales.messaging.bodreply.ShowElectronicCatalog#initializeCatalogEntriesSearch(com.ibm.commerce.search.beans.AdvancedCatEntrySearchListDataBean, * com.ibm.commerce.telesales.messaging.bodreply.SearchCriteria)
    */
    protected void initializeCatalogEntriesSearch(
    AdvancedCatEntrySearchListDataBean abnCatalogEntriesSearch, SearchCriteria aSearchCriteria) {
    final String METHODNAME = "initializeCatalogEntriesSearch";
    ECTrace.entry(ECTraceIdentifiers.COMPONENT_MESSAGING, CLASSNAME, METHODNAME);
    /*
    * Call the superclass to set the default values in the
    abnCatalogEntriesSearch data bean. 
    */
    super.initializeCatalogEntriesSearch(abnCatalogEntriesSearch, aSearchCriteria);
    
    /*
    * Initialize variables to hold information about the search
    criteria.
    */
    String searchMfPartNumberCriteria = "";
    String searchMfPartNumberCriteriaOp =
    SearchConstants.OPERATOR_EQUAL;
    String searchMfPartNumberCriteriaCaseSensitive = "";
    
    /*
    * Constants used to identify whether the search is
    case-sensitive. 
    */
    String SEARCH_CASE_SENSITIVE_YES = "yes";
    String SEARCH_CASE_SENSITIVE_NO = "no";
    
    /*
    * The value of the string passed to getSelectExpression must match
    the
    <code>findCriteriaFieldName</code> 
    * property in the plugin.xml file on the IBM Sales Center client.
    * In this tutorial, the plugin.xml file is located in
    MyNewExtensionPlugin, and
    * the property is specified in the following line: 
    *
    <code>&lt;property name="findCriteriaFieldName"
    value="ManufacturerPartNum"&gt;</code>
    */
    SelectExpression selectExpressionMfPartNumber = aSearchCriteria
    .getSelectExpression("ManufacturerPartNum"); 
    
    /*
    * Extract information about the search criteria from
    <code>selectExpressionMfPartNumber</code>.
    */
    
    if (null != selectExpressionMfPartNumber) {
    
    searchMfPartNumberCriteria =
    selectExpressionMfPartNumber.getValue();
    searchMfPartNumberCriteriaCaseSensitive =
    selectExpressionMfPartNumber.isCaseSensitive() ?
    SEARCH_CASE_SENSITIVE_YES
    : SEARCH_CASE_SENSITIVE_NO;
    searchMfPartNumberCriteriaOp =
    getSearchTypeValue(selectExpressionMfPartNumber.getSearchType());
    }
    
    /*
    * If the manufacturer part number search criteria is not null, extract the search criteria information
    * and set its values in the abnCatalogEntriesSearch data bean. 
    */
    try {
        if (searchMfPartNumberCriteria != null &&
    !searchMfPartNumberCriteria.equalsIgnoreCase("")) {
           
    abnCatalogEntriesSearch.setManufacturerPartNum(searchMfPartNumberCriteria);
           
    abnCatalogEntriesSearch.setManufacturerPartNumOperator(searchMfPartNumberCriteriaOp);
           
    abnCatalogEntriesSearch.setManufacturerPartNumCaseSensitive(searchMfPartNumberCriteriaCaseSensitive);
         }
    }
    catch(Exception e) {
        ECTrace.trace(ECTraceIdentifiers.COMPONENT_MESSAGING, CLASSNAME, METHODNAME, e.toString());
    }
    }
    

  11. Add required import statements to the source code by using the Organize Imports function. Right-click anywhere in the source code for ExtendedShowElectronicCatalog.java and select Source > Organize Imports.

  12. Save the file and keep it open for the next step.

< Previous | Next >


+

Search Tips   |   Advanced Search