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:


  1. 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, called MyMessageKeys that contains the _ERR_CUSTOMER and _ERR_CUSTOMER_INVALID_ID message keys and you put this class in the com.mycompany.messages package. In this case, the class definition appears as follows:

    public class MyMessageKeys
        public static String _ERR_CUSTOMER="_ERR_CUSTOMER";

    Providing String wrappers for message keys allows the compiler to check their validity.

  2. 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 the com.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);
  3. 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 WebSphere Commerce messages.

    To continue the MyNewMessages example, create a text file by the name of Place the messages in the appropriate directory:

    single store servlet
    WebSphere Commerce Developer workspace_dir\Stores\Web Content\WEB-INF\classes\storeDirwhere storeDir is the name of your store.
    WebSphere Commerce Accelerator
    WebSphere Commerce Developer workspace_dir\CommerceAccelerator\Web Content\WEB-INF\classes
    Administration Console
    WebSphere Commerce Developer workspace_dir\SiteAdministration\Web Content\WEB-INF\classes
    Organization Administration Console
    WebSphere Commerce Developer workspace_dir\OrganizationAdministration\Web Content\WEB-INF\classes
    globally by any servlet in the enterprise application
    WebSphere Commerce Developerworkspace_dir\WebSphereCommerceServer\properties

    The preceding directories are specified within the context of the development environment. Once you have completed testing in that environment, refer to Stages of deploying customized assets for information about deploying to the target WebSphere Commerce Server. The messages can also be within the WebSphereCommerceExtensionLogic project.

    Since the properties file contains pairs of message keys and the corresponding message text, the file contains the following lines:

    _ERR_CUSTOMER_MESSAGE = The customer message "{0}".
    _ERR_CUSTOMER_INVALID_ID = Invalid ID "{0}".