Defining search

As part of creating a custom tool for the Management Center, you define an OpenLaszlo library class for each search definition.

Feature Pack 2Feature Pack 3As part of creating a custom tool for the Management Center, you define search definitions for each search type.

About this task

This task file provides the generic steps for defining a search definition. For more information about search definitions before you start to define a search definition, see wcfSearchDefinition.

Procedure

  1. Complete one of the following steps:
    • WebSphere Commerce Version 7.0.0.0Feature Pack 1In the Enterprise Explorer view, expand LOBTools > WebContent > WEB-INF > src > lzx > mycompany > recipe.
    • Feature Pack 2Feature Pack 3In the Enterprise Explorer view, expand LOBTools > WebContent > config > mycompany > recipe.
  2. Create a directory that is named searchDefinitions if the directory does not exist.
  3. Right-click the searchDefinitions folder and select Import. Expand General and select File system.
  4. Click Next, then click Browse. Go to the following directory
    OptionDescription
    WebSphere Commerce Version 7.0.0.0Feature Pack 1TutorialSource\LOBTools\WebContent\WEB-INF\src\lzx\mycompany\recipe\searchDefinitions, where TutorialSource is the location where you extracted the Tutorial sample source code WebSphere Commerce Version 7.0.0.0Feature Pack 1
    1. Select the FindRecipesSearchDefinition.lzx file.
    2. Click Finish to import the file.
    Feature Pack 2Feature Pack 3TutorialSource\LOBTools\WebContent\config\mycompany\recipe\searchDefinitions, where TutorialSource is the location where you extracted the Tutorial sample source code Feature Pack 2Feature Pack 3
    1. Select the FindRecipesSearchDefinition.def file.
    2. Click Finish to import the file.
  5. Open one of the following files and examine the contents:
    • WebSphere Commerce Version 7.0.0.0Feature Pack 1FindRecipesSearchDefinition.lzx (search class file)
    • Feature Pack 2Feature Pack 3FindRecipesSearchDefinition.def (search definition file)
    OptionDescription
    WebSphere Commerce Version 7.0.0.0Feature Pack 1FindRecipesSearchDefinition.lzx WebSphere Commerce Version 7.0.0.0Feature Pack 1The following code sample shows two search classes, one for the Recipe object and the other for the Recipe Collection, which is defined within a search class file.
    
    <library>    
            <!-- Search for Recipe -->
            1 <class name="recFindRecipesSearchDefinition"  extends="wcfSearchDefinition" 
                            2 searchType="FindRecipes" 
                            displayName="Recipes" 
                            isDefault="true" 
                            3 listClass="recRecipeSearchGrid">
                    <wcfSearchService name="FindRecipes" url="/cmc/FindRecipes">
                            <wcfServiceParam name="storeId"/>                       
                    </wcfSearchService>
            </class>
            <!-- Search for Recipe Collection -->
            <class name="recFindRecipeCollectionsSearchDefinition"  extends="wcfSearchDefinition" 
                            searchType="FindRecipeCollections" 
                            displayName="Recipe Collections" 
                            isDefault="false" 
                            listClass="recCollectionGrid">
                    4 <wcfSearchService name="FindRecipeCollections" url="/cmc/FindRecipeCollections">
                            <wcfServiceParam name="storeId"/>                       
                    </wcfSearchService>
            </class>  
    </library>
    
    1 recFindRecipesSearchDefinition
    Used to define the search on recipes.
    2 searchType
    Must be consistent with the searchType property of the corresponding primary object definition.
    3 listClass
    Sets the search result list grid.
    4 wcfSearchService
    Sets the search service to be called to run the query. The query is mapped to the URL "/cmc/FindRecipes" in the lesson: Retrieving Management Center objects by transforming Nouns into XML.
    Feature Pack 2Feature Pack 3FindRecipesSearchDefinition.def Feature Pack 2Feature Pack 3The following code sample shows two search definitions, one for the Recipe object and the other for the Recipe Collection, which is defined within a search definition file.
    <Definitions>
    	<!-- Search for Recipe -->
    1 <SearchDefinition definitionName="FindRecipes"
    			2 searchType="FindRecipes"
    			displayName="Recipes"
    			isDefault="true"
    			3 listDefinitionName="recRecipeSearchGrid">
    		4 <SearchService name="FindRecipes" url="/cmc/FindRecipes">
    			<ServiceParam name="storeId"/>
    		</SearchService>
    	</SearchDefinition>
    	<!-- Search for Recipe Collection -->
    	<SearchDefinition definitionName="FindRecipeCollections"
    			searchType="FindRecipeCollections"
    			displayName="Recipe Collections"
    			isDefault="false"
    			listDefinitionName="recCollectionGrid">
    		<wcfSearchService name="FindRecipeCollections"
    				url="/cmc/FindRecipeCollections">
    			<ServiceParam name="storeId"/>                       
    		</SearchService>
    	</SearchDefinition>  
    </Definitions>
    1 FindRecipes
    Used to define the search on recipes.
    2 searchType
    Must be consistent with the searchType attribute of the corresponding primary object definition.
    3 listDefinitionName
    Sets the search results list grid.
    4 SearchService
    Sets the search service to be called to run the query. The query is mapped to the URL "/cmc/FindRecipes" in the lesson: Retrieving Management Center objects by transforming Nouns into XML.
  6. After you define the search definition, you need to configure the search type to the primary object.
    1. Complete one of the following steps:
      1. WebSphere Commerce Version 7.0.0.0Feature Pack 1In the Enterprise Explorer view, expand LOBTools > WebContent > WEB-INF > src > lzx > mycompany > recipe > objectDefinitions.
      2. Feature Pack 2Feature Pack 3In the Enterprise Explorer view, expand LOBTools > WebContent > config > mycompany > recipe > objectDefinitions.
    2. Open the primary object definition file:
      • WebSphere Commerce Version 7.0.0.0Feature Pack 1RecipePrimaryObjectDefinition.lzx
      • Feature Pack 2Feature Pack 3RecipePrimaryObjectDefinition.def
    3. Find the Recipe and RecipeCollection object definitions and the searchType attribute for these object definitions.
      The following code samples show the searchType attribute for the Recipe and RecipeCollection object definitions, in boldface.WebSphere Commerce Version 7.0.0.0Feature Pack 1
      
      <class name="recRecipePrimaryObjectDefinition" extends="wcfPrimaryObjectDefinition"
                      objectType="Recipe"
                      creatable="true"
                      displayName="${extRecipeResources.recipe_DisplayName.string}"
                      displayNameProperty="name"
                      idProperty="recipeId"
                      searchType="FindRecipes"
                      newDisplayName="${extRecipeResources.recipe_NewDisplayName.string}"
                      propertiesClass="recRecipeProperties"
                      icon="productIcon"
                      headerIcon="productHeaderIcon"  
                      >                    
              ... ...
              ... ...
      </class>
      
      <class name="recRecipeCollectionPrimaryObjectDefinition" extends="wcfPrimaryObjectDefinition"
                      creatable="true"
                      idProperty="collectionId"
                      objectType="RecipeCollection"
                      searchType="FindRecipeCollections" 
                      displayName="${extRecipeResources.recipeCollection_DisplayName.string}"
                      displayNameProperty="collectionName"  
                      newDisplayName="${extRecipeResources.recipeCollection_NewDisplayName.string}"
                      propertiesClass="recCollectionProperties" 
                      >                            
              ... ...
              ... ...
      </class>
      
      Feature Pack 2Feature Pack 3
      <PrimaryObjectDefinition definitionName="Recipe"
      		objectType="Recipe"
      		creatable="true"
      		displayName="${extRecipeResources.recipe_DisplayName}"
      		displayNameProperty="name"
      		idProperty="recipeId"
      		searchType="FindRecipes"
      		newDisplayName="${extRecipeResources.recipe_NewDisplayName}"
      		propertiesDefinitionName="recRecipeProperties"
      		icon="productIcon"
      		headerIcon="productHeaderIcon">                    
      	... ...
      	... ...
      </PrimaryObjectDefinition>
      
      <PrimaryObjectDefinition definitionName="RecipeCollection"
      		creatable="true"
      		idProperty="collectionId"
      		objectType="RecipeCollection"
      		searchType="FindRecipeCollections"
      		displayName="${extRecipeResources.recipeCollection_DisplayName}"
      		displayNameProperty="collectionName"
      		newDisplayName="${extRecipeResources.recipeCollection_NewDisplayName}"
      		propertiesDefinitionname="recCollectionProperties">                            
      	... ...
      	... ...
      </PrimaryObjectDefinition>
  7. WebSphere Commerce Version 7.0.0.0Feature Pack 1Right-click the LOBTools project and select Build OpenLaszlo Project.