Creating a custom validator

Create a custom validation rule for use in the Management Center user interface. For example, you can add a rule to validate that there are no spaces in a value that is entered by the business user. In addition to creating a validation rule within the Management Center client, you need to create the server-side validation logic.

Procedure

  1. Open HCL Commerce Developer and switch to the Enterprise Explorer view.
  2. Expand LOBTools > WebContent > WEB-INF > src > xml > mycompany > component > objectDefinitions, where mycompany is the name of your company, and component is the name of the Management Center component. If the mycompany directory structure does not exist for storing your custom definition files, you must create this directory structure.
  3. Create a definition file to include the definition for your new validation rule.
    Name the file with the format, mycompanycomponentValidator.xml
    , such as MyCompanyCatalogValidator.xml.
  4. Within your new definition file, include the definition for your validation rule.
    For example, the following code defines a validation rule that extends the validator class. This validator verifies that the value specified by the business user does not contain spaces.
    
    <!-- This class validates that a property value does not contain spaces.
      -->
    <class name="extNoSpacesValidator" extends="wcfValidator">
      <method name="validate" args="o, property">
        <![CDATA[ if (property){
        if (property.value.indexOf(" ") >= 0) {
        property.addValidationError(this, "Enter a value with no spaces for the <b>" +
        property.propertyDefinition.displayName + "</b> field.");
        }
        else {
        property.clearValidationError(this);
        }
        }
          ]]>
      </method>
    </class>   

What to do next

With your custom validation rule created, you can add the rule to an object definition to apply the validation rule to an object property. For more information, see Adding a validation rule.