Adding a validation rule

Add a validation rule where one does not exist in the Management Center user interface. For example, you can add a rule to validate that the business user has entered a value for a mandatory field. In addition to creating a validation rule on the client-side, you also need to create the validation logic on the server-side.

About this task

Tip: This task file provides the generic steps for adding a validation rule. For a tutorial on this topic, refer to Tutorial: Adding a validation rule in the Marketing tool.

To add a validation rule to the Management Center:

Procedure

  1. Open WebSphere Commerce Developer and switch to the Enterprise Explorer view.
  2. 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 > commerce > Management_Center_component > objectDefinitions, where Management_Center_component is the name of the tool you want to customize. Validation rules are declared as part of the object definition.
    • Introduced in Feature Pack 2In the Enterprise Explorer view, expand LOBTools > WebContent > config > commerce > Management_Center_component > objectDefinitions, where Management_Center_component is the name of the tool you want to customize. Validation rules are declared as part of the object definition.
  3. Identify the file that contains the object definition that you want to add the validation rule to. Open the file and locate:
    • WebSphere Commerce Version 7.0.0.0Feature Pack 1the object definition class
    • Introduced in Feature Pack 2the objection definition
  4. Update the object definition with the new validation rule. There are three ways to add validation rules to an object definition.
    1. Specify values for the following property definition attributes: maximumSize, maxValue, minValue, required or type. For example, in the following property definition required is set to true and maximumSize is set to 254. This framework will display validation errors if the identifier property is blank or exceeds 254 characters.
      WebSphere Commerce Version 7.0.0.0Feature Pack 1
      <wcfPropertyDefinition
         displayName="${catalogResources.categoryCode_DisplayName.string}" 
         propertyName="identifier" type="string" required="true" maximumSize="254"/> 
      </wcfPropertyDefinition>
      Introduced in Feature Pack 2
      <PropertyDefinition
         displayName="${catalogResources.categoryCode_DisplayName}" 
         propertyName="identifier" type="string" required="true" maximumSize="254"/> 
      </PropertyDefinition>
    2. Complete one of the following steps:
      Option Description
      Instantiate an instance of a class that extends lzx/commerce/foundation/restricted/Validator.lzx/wcfValidator as a child element of an instance of lzx/commerce/foundation/restricted/PropertyDefinition.lzx/wcfPropertyDefinition In the following example, the identifier property definition is modified to include a custom validator that verifies that the identifier does not contain spaces.
      <wcfPropertyDefinition
         displayName="${catalogResources.categoryCode_DisplayName.string}"
         propertyName="identifier" type="string" required="true" maximumSize="254">
         <extNoSpacesValidator/>
      </wcfPropertyDefinition> 
      Declare a definition element that extends lzx/commerce/foundation/restricted/Validator.lzx/wcfValidator as a child element of a PropertyDefinition element In the following example, the identifier property definition is modified to include a custom validator that verifies that the identifier does not contain spaces. The class name of the custom validator is extNoSpacesValidator.
      <PropertyDefinition
         displayName="${catalogResources.categoryCode_DisplayName}"
         propertyName="identifier" type="string" required="true" maximumSize="254">
         <NoSpacesValidator package="ext"/>
      </PropertyDefinition> 
    3. Complete one of the following steps:
      Option Description
      Instantiate an instance of a class that extends wcfValidator as a child element of an object definition (lzx/commerce/foundation/restricted/ObjectDefinition.lzx/wcfObjectDefinition) This type of validator is called an object level validator. Object level validators are used to validate multiple property values or child objects.
      The following example demonstrates the declaration of an object level validator that ensures that there are no duplicate offer prices.
      <class name="catBaseCatalogGroupSKUPrimaryObjectDefinition" 
         extends="wcfPrimaryObjectDefinition"
         baseType="catBaseCatalogEntryPrimaryObjectDefinition"
         isBaseDefinition="true"
         objectGroups="CatalogEntry,SKUs,CatalogGroupSKUs"
         idProperty="catentryId"
         propertiesClass="catCatalogGroupSKUProperties" 
         displayName="${catalogResources.displayNameCategoryLevelSKU.string}"
         newDisplayName="${catalogResources.displayNameNewCategoryLevelSKU.string}"
         displayNameProperty="partnumber"
         searchType="FindAllCatalogEntries"
         helpLink="tasks/tpngen1s.htm">
         
         ...
         <!--
         Validator to check for duplicates in the offer price minimum quantity values.
          -->
         <catOfferPriceMinimumQuantityUniquenessValidator /> 
      
      </class>
      Declare a definition element that extends wcfValidator as a child element of an object definition (lzx/commerce/foundation/restricted/ObjectDefinition.lzx/wcfObjectDefinition). This type of validator is called an object level validator. Object level validators are used to validate multiple property values or child objects.
      The following example demonstrates the declaration of an object level validator that ensures that there are no duplicate offer prices. The class name of the validator is catOfferPriceMininmumQuantityUniquenessValidator.
      <PrimaryObjectDefinition
      	definitionName=
      		"catBaseCatalogGroupSKUPrimaryObjectDefinition" 
      	baseDefinitionName="catBaseCatalogEntryPrimaryObjectDefinition"
      	isBaseDefinition="true"
      	objectGroups="CatalogEntry,SKUs,CatalogGroupSKUs"
      	idProperty="catentryId"
      	propertiesClass="catCatalogGroupSKUProperties" 
      	displayName="${catalogResources.displayNameCategoryLevelSKU}"
         	newDisplayName="${catalogResources.displayNameNewCategoryLevelSKU}"
      	displayNameProperty="partnumber"
         	searchType="FindAllCatalogEntries"
         	helpLink="tasks/tpngen1s.htm">
         
      	...
      	<!--
         		Validator to check for duplicates in the offer price
      		minimum quantity values.
      	-->
         	<OfferPriceMinimumQuantityUniquenessValidator package="cat"/> 
      
      </PrimaryObjectDefinition>

What to do next

After you complete your customization:
Version Steps
  1. Right-click LOBTools Project; then click Build OpenLaszlo Project to produce an updated ManagementCenter.swf file under the workspace_dir\LOBTools\WebContent directory. This setting is the default environment setting.
  2. Test your changes by viewing them in the Management Center, using this URL: https://hostname:8000/lobtools.
  3. Deploy your changes to your production environment.
Introduced in Feature Pack 2
  1. Test your changes by viewing them in the Management Center, using this URL: https://hostname:8000/lobtools.
  2. Deploy your changes to your production environment.