Defining the new search definition by extending the wcfSearchDefinition class

This lesson introduces how to extend the search widget in the Management Center to display the new search option, and how to define the new search definition by extending the wcfSearchDefinition class.In the Management Center, all search options are defined by extending this class ( wcfSearchDefinition).

About this task

All properties and methods are predefined, you can use them directly to define your search.

Procedure

  1. Open WebSphere Commerce Developer.
  2. Complete one of the following steps:
    • WebSphere Commerce Version 7.0.0.0Feature Pack 1In the Enterprise Explorer view, navigate to LOBTools > WebContent > WEB-INF > src > lzx > mycompany > catalog > searchDefinitions. If the file path does not exist, create the necessary folders as shown in the following steps:
      1. Right-click lzx and select New > Other > Simple > Folder to create a new folder.
      2. In the Folder name field, type mycompany, click Next, and then click Finish .
      3. Right-click the new mycompany folder and select New > Other > Simple > Folder to create a new folder within the mycompany folder.
      4. In the Folder name field, type catalog, click Next, and then click Finish.
      5. Right-click the new catalog folder and select New > Other > Simple > Folder to create a new folder within the catalog folder.
      6. In the Folder name field, type searchDefinitions, click Next, and then click Finish.
    • Feature Pack 2Feature Pack 3In the Enterprise Explorer view, navigate to LOBTools > WebContent > config > mycompany > catalog > searchDefinitions. If the file path does not exist, create the necessary folders as shown in the following steps:
      1. Right-click config and select New > Other > Simple > Folder to create a new folder.
      2. In the Folder name field, type mycompany , click Next , and then click Finish .
      3. Right-click the new mycompany folder and select New > Other > Simple > Folder to create a new folder within the mycompany folder.
      4. In the Folder name field, type catalog, click Next, and then click Finish.
      5. Right-click the new catalog folder and select New > Other > Simple > Folder to create a new folder within the catalog folder.
      6. In the Folder name field, type searchDefinitions, click Next, and then click Finish.
  3. To create the new search definition file, right-click searchDefinitions and select New > Other > Simple > File.
  4. In the File name field, type one of the following file names; click Next and Finish.
    • WebSphere Commerce Version 7.0.0.0Feature Pack 1FindAllCatalogEntriesByWarrantySearchDefinition.lzx
    • Feature Pack 2Feature Pack 3FindAllCatalogEntriesByWarrantySearchDefinition.def
  5. Complete one of the following steps:
    OptionDescription
    WebSphere Commerce Version 7.0.0.0Feature Pack 1FindAllCatalogEntriesByWarrantySearchDefinition.lzx WebSphere Commerce Version 7.0.0.0Feature Pack 1In this class file:
    1. Copy and paste the following sample code:
      <library>
              <class name="extFindAllCatalogEntriesByWarrantySearchDefinition" extends="wcfSearchDefinition"
                          1 searchType="FindAllCatalogEntriesByWarranty"
                          2 displayName="${extCatalogResources.findAllCatalogEntriesByWarrantySearchDefinition_DisplayName.string}"
                          3 isDefault="false"
                          4 listClass="catCatalogEntrySearchGrid"
                          5 listTitle="${catalogResources.catalogGroupChildListTitle.string}">
                          
                          6 <wcfSearchService name="findAllCatalogEntriesByWarranty" url="/cmc/FindCatalogEntries-ByWarranty">
                                  <wcfServiceParam name="storeId"/>
                                  <wcfServiceParam name="masterCatalogId"/>
                          </wcfSearchService>
              </class>
      </library>
      1 searchType
      A string that identifies the search type. All search definitions declared under the same parent must have unique search types. You can assign the FindAllCatalogEntriesByWarranty search type to this newly defined search definition.
      2 displayName
      The text displayed in the search widget for this search type. The value for displayName is defined in the property file, and is referred to here by using its resource bundle.
      3 isDefault
      This attribute that declares this wcfSearchDefinition as the default search type. Set this attribute to false to indicate that this search definition is not the default search type in wcfSearchDefinition.
      4 listClass
      This attribute contains the name of the class to use for displaying the search results view. Use the catCatalogEntrySearchGrid class, which was customized with extended warranty properties in Extending the Catalog Search Result list view to display search results with extended properties of Tutorial: Adding new search conditions in the advanced search of the Catalogs tool.
      5 listTitle
      The title to use in the search results view. Keep the default value of "Product".
      6 wcfSearchService
      This element is a child of wcfSearchDefinition and defines the service name and parameters that are used to perform the search.
      name
      The name of the wcfSearchService class.
      url
      The service URL to call. The URL is a Struts action path defined in the struts-extension.xml file. Use /cmc/FindCatalogEntries-ByWarranty, defined in Create new controller JSP file to retrieve and mediate the Management Center object.
      wcfServiceParam
      Declares the service parameters that are resolved before invoking the parent service. Use storeId and masterCatalogId for wcfServiceParam; these are default parameters for the search service.
    2. Save and close the file.
    Feature Pack 2Feature Pack 3FindAllCatalogEntriesByWarrantySearchDefinition.def Feature Pack 2Feature Pack 3In this definition file:
    1. Copy and paste the following sample code:
      <Definitions>
          <SearchDefinition 1 definitionName="FindAllCatalogEntriesByWarranty"
              2 searchType="FindAllCatalogEntriesByWarranty"
              3 displayName=
      "${extCatalogResources.findAllCatalogEntriesByWarrantySearchDefinition_DisplayName}"
              4 isDefault="false"
              5 listDefinitionName="catCatalogEntrySearchGrid"
              6 listTitle="${catalogResources.catalogGroupChildListTitle}">
              7 <SearchService name="findAllCatalogEntriesByWarranty"
                  url="/cmc/FindCatalogEntries-ByWarranty">
                  <ServiceParam name="storeId"/>
                  <ServiceParam name="masterCatalogId"/>
              </SearchService>
          </SearchDefinition>
      </Definitions>
      1 definitionName
      The unique name for the definition. To ensure that the definition can be located when it is not explicitly included in the business object editor definition, always specify the same value for the definitionName and the searchType.
      2 searchType
      A string that identifies the search type. All search definitions declared under the same parent must have unique search types. You can assign the FindAllCatalogEntriesByWarranty search type to this newly defined search definition.
      3 displayName
      The text displayed in the search widget for this search type. The value for displayName is defined in the property file, and is referred to here by using its resource bundle.
      4 isDefault
      This attribute that declares this wcfSearchDefinition as the default search type. Set this attribute to false to indicate that this search definition is not the default search type in wcfSearchDefinition.
      5 listDefinitionName
      This attribute contains the name of the definition to use for displaying the search results view. Use the catCatalogEntrySearchGrid definition, which was customized with extended warranty properties in Extending the Catalog Search Result list view to display search results with extended properties of Tutorial: Adding new search conditions in the advanced search of the Catalogs tool.
      6 listTitle
      The title to use in the search results view. Keep the default value of "Product".
      7 SearchService
      This element is a child of SearchDefinition and defines the service URL and parameters that are used to perform the search.
      name
      The name of the SearchService definition.
      url
      The service URL to call. The URL is a Struts action path defined in the struts-extension.xml file. Use /cmc/FindCatalogEntries-ByWarranty, defined in Create new controller JSP file to retrieve and mediate the Management Center object.
      ServiceParam
      Declares the service parameters that are resolved before invoking the parent service. Declare storeId and masterCatalogId for ServiceParam; these are default parameters for the search service.
    2. Save and close the file.
  6. WebSphere Commerce Version 7.0.0.0Feature Pack 1Register the FindAllCatalogEntriesByWarrantySearchDefinition.lzx file in the CatalogExtensionsLibrary.lzx library:
    1. In the Enterprise Explorer view, navigate to LOBTools > WebContent > WEB-INF > src > lzx > commerce > catalog
    2. Double-click CatalogExtensionsLibrary.lzx to open it in the default editor.
    3. In the library section, add a new line to include the new advanced search class:
      <include href = "../../mycompany/catalog/searchDefinitions/FindAllCatalogEntriesByWarrantySearchDefinition.lzx" />
    4. Save and close the file.
  7. WebSphere Commerce Version 7.0.0.0Feature Pack 1Right-click the LOBTools folder; then click Build OpenLaszlo Project. The project builds.

Results