Tutorials > Management Center > Add a Recipes tool to the Management Center

< Previous | Next >


Define child objects and reference objects for a primary object

Your custom tool can include child objects and reference objects on which the primary object depends. In this lesson you define an OpenLaszlo library class or a definition file for all child and reference object definitions.

A child object definition describes a secondary business object. A child cannot exist without a parent object.

To declare that an object has child objects of a specific type, create an instance of the child object definition as a child of the parent object definition. For example, a product description is a child object of the product in the Catalogs tool.

The reference object is a special type of child object that describes a relationship between two primary objects. For example, a merchandising association is a reference object describing a relationship between two product objects.

The Recipe primary object has three child object definitions, RecipeDescription, RecipeIngredients and RecipeInstruction and one reference object, RecipeAssociation.


Procedure

  1. Complete one of the following steps:

    • In the Enterprise Explorer view, expand LOBTools > WebContent > WEB-INF > src > lzx > mycompany > recipe > objectDefinitions.

    • In the Enterprise Explorer view, expand LOBTools > WebContent > config > mycompany > recipe > objectDefinitions.

  2. Right-click the objectDefinitions folder and select Import. Expand General and select File system.

  3. Click Next, then click Browse and navigate to:

    Option Description
    TutorialSource\LOBTools\WebContent\WEB-INF\src\lzx\mycompany\recipe\objectDefinitions, where TutorialSource is the location where you unzipped the Tutorial sample source code

    1. Select the RecipeCommonObjectDefinition.lzx file.

    2. Click Finish to import the file.
    TutorialSource\LOBTools\WebContent\config\mycompany\recipe\objectDefinitions, where TutorialSource is the location where you unzipped the Tutorial sample source code

    1. Select the RecipeCommonObjectDefinition.def file.

    2. Click Finish to import the file.

  4. Open one of the following files and examine the contents:

    • RecipeCommonObjectDefinition.lzx (common object class file)

    • RecipeCommonObjectDefinition.def (common object definition file)

    The child objects and reference objects are defined within these files.

    The following code samples show child objects and reference objects defined in a common object file:

    Option Description
    RecipeCommonObjectDefinition.lzx

    < 1  class name="recRecipeIngredientsDefinition" extends="wcfChildObjectDefinition"
               idProperty="ingredientId"
               objectType="RecipeIngredients"
               creatable="true" 
               displayName="${extRecipeResources.ingredientsName_ColumnHeader.string}"
               displayNameProperty="ingredientName"
               newDisplayName="${extRecipeResources.ingredients_NewDisplayName.string}"
               propertiesClass="recManageRecipeIngredients" 
               openGroupTop="true" 
               icon="definingAttributeIcon"
               headerIcon="definingAttributeHeaderIcon" >
    
           
    <!-- Property Definition -->
           
    <wcfPropertyDefinition displayName="${extRecipeResources.ingredientsQuantity_ColumnHeader.string}" 
                    propertyName="amount" type="number"/>            
           
    <!-- Create Service -->
           
    <wcfCreateService url="/cmc/CreateRecipeIngredients">
                   
    <wcfServiceParam name="storeId"/>
                   
    <wcfServiceParam name="recipeId" parentProperty="true"/>              
                   
    <wcfServiceParam name="languageId"/>
                   
    <wcfServiceParam name="ingredientDesc" objectPath="RecipeIngredientsDescription" propertyName="ingredientDesc" sendEmpty="false" optional="true"/>
                   
    <wcfServiceParam name="catentryId" objectPath="RecipeIngredientsReference/CatalogEntry" propertyName="catentryId" sendEmpty="false" optional="true"/>
           
    </wcfCreateService>       
           
    <!-- Update Service -->   
           
    <wcfUpdateService url="/cmc/UpdateRecipeIngredients">                                   
                   
    <wcfServiceParam name="storeId" parameterName="storeId">   
                   
    <wcfEnablementCondition conditionId="localstoreid" propertyName="recipetype" enablementValue="Recipe"/>
           
    </wcfServiceParam>                
           
    <!-- Delete Service -->                   
           
    <wcfDeleteService url="/cmc/DeleteRecipeIngredients">           
                   
    <wcfServiceParam name="storeId"/>
                   
    <wcfServiceParam name="recipeId" parentProperty="true"/>
                   
    <wcfServiceParam name="ingredientId" propertyName="ingredientId" />                   
           
    </wcfDeleteService>       
           
           
    <!-- Include all child object definition-->   
           
    <recRecipeIngredientsDescription/>                
    </class>
            
     2 
    <class name="recRecipeAssociationDefinition" extends="wcfReferenceObjectDefinition"           
            creatable="true" 
            objectType="RecipeAssociation" 
            idProperty="associationId"
            copyProtected="false"
           referencedTypes="Product, InheritedProduct"> 
           
    <!-- Create Service -->
           
    <wcfCreateService url="/cmc/CreateRecipeAssociation" sendAll="false"> 
                   
    <wcfServiceParam name="storeId"/>
                   
    <wcfServiceParam name="catentryId" objectPath="CatalogEntry" propertyName="catentryId"/>
                   
    <wcfServiceParam name="recipeId" parentProperty="true"/>
           
    </wcfCreateService>
           
    <!-- Delete Service -->
           
    <wcfDeleteService url="/cmc/DeleteRecipeAssociation" sendAll="false">
                   
    <wcfServiceParam name="storeId"/>
                   
    <wcfServiceParam name="catentryId" objectPath="CatalogEntry" propertyName="catentryId"/>
                   
    <wcfServiceParam name="recipeId" parentProperty="true"/>
           
    </wcfDeleteService>                         
                  
    </class>  
    

    RecipeCommonObjectDefinition.def

     1 
    <ChildObjectDefinition definitionName="recRecipeIngredientsDefinition"
            idProperty="ingredientId"
            objectType="RecipeIngredients"
            creatable="true"
            displayName="${extRecipeResources.ingredientsName_ColumnHeader}"
            displayNameProperty="ingredientName"
            newDisplayName="${extRecipeResources.ingredients_NewDisplayName}"
            propertiesDefinitionName="recManageRecipeIngredients"
            openGroupTop="true"
            icon="definingAttributeIcon"
            headerIcon="definingAttributeHeaderIcon">
    
        <!-- Property Definition -->
          
    <PropertyDefinition
            displayName=
                "${extRecipeResources.ingredientsQuantity_ColumnHeader}"
            propertyName="amount"
            type="number"/>
        <!-- Create Service -->
        <CreateService url="/cmc/CreateRecipeIngredients">
            <ServiceParam name="storeId"/>
            <ServiceParam name="recipeId" parentProperty="true"/>
            <ServiceParam name="languageId"/>
            <ServiceParam name="ingredientDesc"
                objectPath="RecipeIngredientsDescription"
                propertyName="ingredientDesc" sendEmpty="false" optional="true"/>
            <ServiceParam name="catentryId"
                objectPath="RecipeIngredientsReference/CatalogEntry"
                propertyName="catentryId" sendEmpty="false" optional="true"/>
        </CreateService>
        <!-- Update Service -->
        <UpdateService url="/cmc/UpdateRecipeIngredients">
            <ServiceParam name="storeId" parameterName="storeId">
                <EnablementCondition conditionId="localstoreid"
                    propertyName="recipetype" enablementValue="Recipe"/>
            </ServiceParam>
        </UpdateService>
        <!-- Delete Service -->
        <DeleteService url="/cmc/DeleteRecipeIngredients">
            <ServiceParam name="storeId"/>
            <ServiceParam name="recipeId" parentProperty="true"/>
            <ServiceParam name="ingredientId" propertyName="ingredientId"/>
           
    </DeleteService>       
    
        <!-- Include all child object definition-->   
        <ChildObjectDefinition baseDefinitionName="recRecipeIngredientsDescription"/>
    </ChildObjectDefinition>
    
     2 
    <ReferenceObjectDefinition definitionName="recRecipeAssociationDefinition"
        creatable="true"
        objectType="RecipeAssociation"
        idProperty="associationId"
        copyProtected="false"
        referencedTypes="Product, InheritedProduct">
        <!-- Create Service -->
        <CreateService url="/cmc/CreateRecipeAssociation" sendAll="false">
            <ServiceParam name="storeId"/>
            <ServiceParam name="catentryId" objectPath="CatalogEntry"
                propertyName="catentryId"/>
            <ServiceParam name="recipeId" parentProperty="true"/>
        </CreateService>
        <!-- Delete Service -->
        <DeleteService url="/cmc/DeleteRecipeAssociation" sendAll="false">
            <ServiceParam name="storeId"/>
            <ServiceParam name="catentryId" objectPath="CatalogEntry"
                propertyName="catentryId"/>
            <ServiceParam name="recipeId" parentProperty="true"/>
        </DeleteService>
    </ReferenceObjectDefinition>
    

     1  recRecipeIngredientsDefinition

    Used as a child object of Recipe to represent the ingredient. It has three properties: name, amount and unit of measurement. Ensure that you define the amount property explicitly, because it is a numerical type. Properties of type string do not need a definition. It has its own create, update and delete services, which are defined in Tutorial: Creating the Project BOD service module. It also has one child object, Ingredient description.

     2  recRecipeAssociationDefinition

    The reference object definition of Recipe, which builds the reference relationship between Recipes and products. It only has create and delete services, which are defined in Tutorial: Creating the Project BOD service module

  5. Right-click the LOBTools project and select Build OpenLaszlo Project.

< Previous | Next >


+

Search Tips   |   Advanced Search