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
To
add a custom validation rule to the Management Center user
interface:
Procedure
- Open
WebSphere Commerce Developer and switch to the Enterprise Explorer
view.
- In the Enterprise Explorer view,
expand
> , 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.
- 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
- Once
you have created the custom validation rule you must add
it to an object definition. See Adding a validation rule.
- Adding a new library to the Management Center