Tutorials > Management Center > Extend simple search in the Catalogs tool
Define 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. All properties and methods are predefined, you can use them directly to define the search.
Procedure
- Open WebSphere Commerce Developer.
- Complete one of the following steps:
- In 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:
- Right-click lzx and select New > Other > Simple > Folder to create a new folder.
- In the Folder name field, type mycompany, click Next, and then click Finish .
- Right-click the new mycompany folder and select New > Other > Simple > Folder to create a new folder within the mycompany folder.
- In the Folder name field, type catalog, click Next, and then click Finish.
- Right-click the new catalog folder and select New > Other > Simple > Folder to create a new folder within the catalog folder.
- In the Folder name field, type searchDefinitions, click Next, and then click Finish.
- In 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:
- Right-click config and select New > Other > Simple > Folder to create a new folder.
- In the Folder name field, type mycompany , click Next , and then click Finish .
- Right-click the new mycompany folder and select New > Other > Simple > Folder to create a new folder within the mycompany folder.
- In the Folder name field, type catalog, click Next, and then click Finish.
- Right-click the new catalog folder and select New > Other > Simple > Folder to create a new folder within the catalog folder.
- In the Folder name field, type searchDefinitions, click Next, and then click Finish.
- To create the new search definition file, right-click searchDefinitions and select New > Other > Simple > File.
- In the File name field, type one of the following file names; click Next and Finish.
- FindAllCatalogEntriesByWarrantySearchDefinition.lzx
- FindAllCatalogEntriesByWarrantySearchDefinition.def
- Complete one of the following steps:
Option Description FindAllCatalogEntriesByWarrantySearchDefinition.lzx In this class file:
- 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 Extend 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.
- Save and close the file.
FindAllCatalogEntriesByWarrantySearchDefinition.def In this definition file:
- 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 Extend 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.
- Save and close the file.
- Register the FindAllCatalogEntriesByWarrantySearchDefinition.lzx file in the CatalogExtensionsLibrary.lzx library:
- In the Enterprise Explorer view, navigate to LOBTools > WebContent > WEB-INF > src > lzx > commerce > catalog
- Double-click CatalogExtensionsLibrary.lzx to open it in the default editor.
- In the library section, add a new line to include the new advanced search class:
<include href = "../../mycompany/catalog/searchDefinitions/FindAllCatalogEntriesByWarrantySearchDefinition.lzx" />
- Save and close the file.
- Right-click the LOBTools folder; then click Build OpenLaszlo Project. The project builds.