Creating messages
If your command throws an ECApplicationException that uses a new message, you must create this new message. Creating a new message involves the following steps:
Procedure
-
Creating a new class that contains the message keys.
The first step in creating new user messages is to create a class that contains the new message keys. A message key is a unique indicator that is used by the logging service to locate the corresponding message text in a resource bundle. This new class should be created within your own package and stored in the WebSphereCommerceServerExtensionsLogic project.
Consider an example, called
MyNewMessages
, in which you create a new class, calledMyMessageKeys
that contains the_ERR_CUSTOMER
and_ERR_CUSTOMER_INVALID_ID
message keys and you put this class in thecom.mycompany.messages
package. In this case, the class definition appears as follows:public class MyMessageKeys { public static String _ERR_CUSTOMER="_ERR_CUSTOMER"; public static String _ERR_CUSTOMER_INVALID_ID="_ERR_CUSTOMER_INVALID_ID"; }
Providing String wrappers for message keys allows the compiler to check their validity.
-
Creating a new class that contains the ECMessage objects.
Within the same package that you created the class for your message keys, create another class that contains the ECMessage objects. The ECMessage class defines the structure of a message object. It is used to retrieve and persist locale-sensitive text messages.
The message object has the following attributes: severity, type, key, resource bundle and associated resource bundle. There are several constructor methods for this class.
Following the MyNewMessages example, create a new class called
MyMessages
within thecom.mycompany.messages
package, as follows:/** * An error message that an invalid customer id was specified. */ public static final ECMessage _ERR_CUSTOMER_INVALID_ID = new ECMessage(WcContentMessageKey._ERR_CUSTOMER_INVALID_ID_REASON_CODE, ECMessageType.USER, WcContentMessageKey._ERR_CUSTOMER_INVALID_ID, USER_RESOURCE_BUNDLE, ECMessageSeverity.ERR, null, null, null);
-
Creating a resource bundle.
You must create a new resource bundle, in which the message keys with corresponding message text are stored. This resource bundle can be implemented either as a Java object, or as a properties file. It is recommended that you use properties files, since they are easier to translate and maintain. Properties files are used for HCL Commerce messages.
To continue the MyNewMessages example, create a text file by the name of
ecCustomerMessages.properties
. Place the messages in the appropriate directory:- single store servlet
- workspace_dir\Stores\Web Content\WEB-INF\classes\storeDirwhere storeDir is the name of your store.
- HCL Commerce Accelerator
- workspace_dir\CommerceAccelerator\Web Content\WEB-INF\classes
- Administration Console
- workspace_dir\SiteAdministration\Web Content\WEB-INF\classes
- Organization Administration Console
- workspace_dir\OrganizationAdministration\Web Content\WEB-INF\classes
- globally by any servlet in the enterprise application
- workspace_dir\WebSphereCommerceServer\properties
The preceding directories are specified within the context of the development environment. The messages can also be within the WebSphereCommerceExtensionLogic project.
Since the properties file contains pairs of message keys and the corresponding message text, the
ecCustomerMessages.properties
file contains the following lines:_ERR_CUSTOMER_MESSAGE = The customer message "{0}". _ERR_CUSTOMER_INVALID_ID = Invalid ID "{0}".