Defining server-side error messages for validation errors
When server validation fails for a Management Center object, you can display an error message to provide more details about the error to users. To display the server-side error message, you must create or change the validation error mapping by defining error reason codes for the validation errors that can occur for a Management Center object. You can then define an error message for the reason codes to provide users with details about the validation errors and potential solutions.
About this task
Procedure
- Open IBM WebSphere Commerce Developer.
-
In the Enterprise Explorer view, expand mycompany is the name of your
company and component is the name of the component for the
object that you want to map to an error code.
, where If the com.mycompany.commerce.component-ext directory does not exist, you must create this directory.
-
Open your custom wc-component-clientobjects-ext.xml
configuration file for the component. If the file does not exist, you must create the file. Use the
file that is provided by WebSphere Commerce for the component as a model for creating your
file.
Note: If you are creating a custom wc-component-clientobjects-ext.xml, register the file within the Spring framework. The spring-extension.xml file is the extension point for the Spring framework in WebSphere Commerce. To use your new validation error mapping, your file must be registered within this file.
- Expand .
- Open the spring-extension.xml file for editing.
- Add a bean definition to include your custom file. Include the definition within a
<bean>
element within the top-level<beans>
element. Your configuration can resemble the following code snippet.<bean class="com.ibm.commerce.foundation.client.facade.bod.servlet.spring.BusinessObjectDocumentConfiguration"> <property name="config" value="/WEB-INF/config/com.mycompany.commerce.component/wc-component-clientobjects.xml" /> </bean>
-
In the error definition configuration section of the file, identify the error configuration for
the object. If the configuration for the object does not exist, create the configuration. Use the
configuration in the file that is provided by WebSphere Commerce as a template.
The error definitions for an object must be included within an
<_config:ErrorGroup
element within the parent<_config:ErrorDefinition
element.For example, the following code snippet shows the error definitions for the catalog identifier property and catalog entry partnumber property.<_config:ErrorDefinitions primaryResourceBundle="com.ibm.commerce.catalog.client.lobtools.properties.CatalogLOBErrorMessages" alternateResourceBundle="extensions.com.ibm.commerce.catalog.client.lobtools.properties.CatalogLOBErrorMessages"> <_config:ErrorGroup name="Catalog"> <_config:ReasonCodeParameterAssociation reasonCode="_ERR_CATALOG_MISSING_IDENTIFIER" parameterName="identifier" /> <_config:ReasonCodeParameterAssociation reasonCode="_ERR_DELETE_OR_UPDATE_NON_EXIST_CATALOG" parameterName="identifier" /> <_config:ReasonCodeParameterAssociation reasonCode="_ERR_CATALOG_DELETE_WITH_TOP_CATEGORY" parameterName="identifier" /> </_config:ErrorGroup> <_config:ErrorGroup name="CatalogEntry"> <_config:ReasonCodeParameterAssociation reasonCode="_ERR_CATENTRY_DUPLICATE_EXTERNAL_IDENTIFIER_FOR_CHANGE" parameterName="partnumber" /> <_config:ReasonCodeParameterAssociation reasonCode="_ERR_CATENTRY_DUPLICATE_PART_NUMBER_FOR_CATENTRY_CREATE" parameterName="partnumber" /> <_config:ReasonCodeParameterAssociation reasonCode="_ERR_CATENTRY_MISSING_PART_NUMBER_FOR_CHANGE" parameterName="partnumber" /> <_config:ReasonCodeParameterAssociation reasonCode="_ERR_CATENTRY_MISSING_PART_NUMBER_FOR_CREATE" parameterName="partnumber" /> </_config:ErrorGroup> </_config:ErrorDefinitions>
-
Add or change the
ReasonCodeMapping
element for the object property to identify the service reason code to associate with the property.If you are adding a reason code, use a<_config:ReasonCodeParameterAssociation>
element to define the reason code.- The value for the
reasonCode
attribute must be the same as the key for the error message text that you add to your custom properties file. - The value for the
parameterName
attribute must be the same as the value for thepropertyName
attribute for the property in the object defintion file.
- The value for the
-
If your reason code does not map to an existing error message, define the error message for the
validation code.