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
- Open HCL Commerce Developer and switch to the Enterprise Explorer view.
- Expand 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. , where
-
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.
-
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>