Tutorials > Management Center > Extend simple search in the Catalogs tool

< Previous | Next >


Create a new expression builder in the get-data-config.xml file

In this lesson, we will define two new expression builders in get-data-config.xml to process the search. These expression builders will be used on the controller JSP file. The first expression builder is used for numeric input search text, and the second one is used for non-numeric input search text.

The expression builder is used by the wcf:getData tag in the controller JSP file to construct an XPath expression that is used by a custom service to retrieve data. All expression builders are defined in the get-data-config.xml file.

To extend the advanced search with the new warranty term and warranty type criteria, extend the expression builder with the new query template and include the new query logic. The base get-data-config.xml file for each component is located in \LOBTools\WebContent\WEB-INF\config\com.ibm.commerce.component\get-data-config.xml . You cannot modify this file directly. Instead, create the \LOBTools\WebContent\WEB-INF\config\com.ibm.commerce.component-ext extension folder to store the extended get-data-config.xml file.

The extension folder and the extended get-data-config.xml file were already defined in Tutorial: Adding new fields in the Catalogs tool. In this tutorial, you only need to open the extended get-data-config.xml file and add the new expression builder definition to the file.

In this lesson, we will define two new expression builders for the new search definition:


Procedure

  1. Open WebSphere Commerce Developer.

  2. In the Enterprise Explorer view, navigate to \LOBTools\WebContent\WEB-INF\config\com.ibm.commerce.catalog-ext and double-click the get-data-config.xml file to open it in the default editor.

    The extension folder and the file are created in a previous tutorial. If the extension folder and file do not exist in the environment, created them by following the steps in Part 1: Adding language insensitive properties in the Catalogs tool of Tutorial: Adding new fields in the Catalogs tool.

  3. In the file editor, locate the line of </wcf:get-data-config>

    Before this line, define the two new expression builders findAllCatentriesByWarrantySearchNumeric and findAllCatentriesByWarrantySearchNonNumeric by pasting the code from the following sample.

    <expression-builder>
        <name>findAllCatentriesByWarrantySearchNumeric</name>
        <data-type-name>CatalogEntry</data-type-name>
        <class>
            com.ibm.commerce.catalog.internal.client.taglib.util.CatalogSearchExpressionBuilder
        </class>
        <method>formatExpression</method>
        <param>
            <name>template</name>
            <value>
                /CatalogEntry[(@catalogEntryTypeCode='$catEntryTypes$') and search(UserData/UserDataField/Warterm='$warterm$' or contains(UserData/UserDataField/Wartype,'$wartype$') or contains(Description/Attributes/careinstruction,'$careinstruction$'))]
            </value>
        </param>
        <param>
            <name>accessProfile</name>
            <value>MyCompany_All</value>
        </param>
    </expression-builder>
    <expression-builder>
        <name>findAllCatentriesByWarrantySearchNonNumeric</name>
        <data-type-name>CatalogEntry</data-type-name>
        <class>
            com.ibm.commerce.catalog.internal.client.taglib.util.CatalogSearchExpressionBuilder
        </class>
        <method>formatExpression</method>
        <param>
            <name>template</name>
            <value>
                /CatalogEntry[(@catalogEntryTypeCode='$catEntryTypes$') and search(contains(UserData/UserDataField/Wartype,'$wartype$')
                or
                contains(Description/Attributes/careinstruction,'$careinstruction$'))]
            </value>
        </param>
        <param>
            <name>accessProfile</name>
            <value>MyCompany_All</value>
        </param>
    </expression-builder>
    

    The meanings of the XML elements are described in the following list:

    name

    The name of the expression builder. The wcf:getData tag in the controller JSP file refers to this name.

    data-type-name

    The name of the data type with which this expression builder definition will be associated. Your search is associated with CatalogEntry

    class

    The fully qualified Java class name of the expression builder. The default is used for Catalog search.

    method

    The method name of the expression builder. This method must accept a java.util.Map and return an instance of com.ibm.commerce.oagis9.datatypes.ExpressionType. The default is used in the example.

    param

    The param element is used to declare parameters that are expected by the expression builder. It is assigned by name and value.

    template

    The search template used to generate the XPath key and locate the SQL statement in the query template file.

    accessProfile

    MyCompany_All is defined in the prerequisite tutorial, Tutorial: Adding new fields in the Catalogs tool to fetch warranty information with catalog entries.

    The data service layer has a specialized convention for UserData in the search mapping, as /UserData/UserDataField/Warterm is not valid XPath. This notation is used to represent the value of the Warterm attribute in the UserData field.

  4. Save and close the file.

< Previous | Next >


+

Search Tips   |   Advanced Search