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 entered by the business user. 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 creating a custom validation rule. For a tutorial on this topic, refer to Tutorial: Adding a validation rule in the Marketing tool.

To add a custom validation rule to the Management Center user interface:

Procedure

  1. Open WebSphere Commerce Developer and switch to the Enterprise Explorer view.
  2. In the Enterprise Explorer view, expand LOBTools > WebContent > WEB-INF > src > lzx > yourCompanyName
    > Management_Center_component > objectDefinitions, where Management_Center_component is the name of the tool you want to customize. You will need to create the folders if they do not exist.
  3. Create the new validation rule as a new OpenLaszlo library source file (name the file using this syntax: company_nameManagement_Center_componentValidator.lzx; for example, MyCompanyCatalogValidator.lzx):
    The following is an example of a validation rule, with the class name extNoSpacesValidator that extends lzx/commerce/foundation/restricted/Validator.lzx/wcfValidator. 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

  1. Once you have created the custom validation rule you must add it to an object definition. See Adding a validation rule.
  2. Adding a new library to the Management Center