Adding a new user message

To incorporate user messages into your user interface elements, you create several assets.

  1. A class which contains the custom messages. WebSphere Commerce implements default messages in the ECToolsMessage class.
  2. A class which maps messages to their corresponding translated entries in resource bundles. WebSphere Commerce uses the ECToolsMessageKey which contains the keys to the default user messages.
  3. A property resource bundle which contains the translatable messages.

Procedure

  1. Create the message class:
    1. In the WebSphere Commerce development environment, navigate to the WebSphereCommerceServerExtensionsLogic project.
    2. Navigate to the src folder.
    3. From the src folder's pop-up menu, select New, and then Package.
    4. In the Name Field on the New Java Package dialog, type a unique name. For the purposes of this scenario, type com.myCompany.messages, where myCompany represents a custom directory name. Packages created by IBM, and included in WebSphere Commerce, follow a naming convention which begins with "com.ibm...". Click Finish to create the package.
    5. Select the com.myCompany.messages folder.
    6. From the folder's pop-up menu, select New, and then Class.
    7. In the Name Field on the New Java Class dialog, enter ECCustomUserMessages, then click Finish. The file opens in the editor.
    8. Create a class similar to the following example:
      
      import com.ibm.commerce.ras.*;
      import com.ibm.commerce.common.*;
      
      public class ECCustomUserMessages {
      
      public final static String EC_SAMPLE_USER_RESOURCE_BUNDLE="com.myCompany.messages.UserMessages";
        
      // sample messages
         public static final ECMessage TOOLS_TEST_USER_ERROR = new ECMessage
          (ECMessageSeverity.ERROR, ECMessageType.USER,ECCustomUserMessagesKey._ERR_TOOLS_TEST_USER_ERROR,EC_SAMPLE_USER_RESOURCE_BUNDLE);
        }
      
    9. Save the file, but do not close the development environment.
  2. Create the class which maps the messages to their corresponding resource bundle keys:
    1. In the WebSphere Commerce development environment, navigate to the WebSphereCommerceServerExtensionsLogic project.
    2. Navigate to the src folder, and then select the com.myCompany.messages folder.
    3. From the folder's pop-up menu, select New, and then Interface.
    4. In the Name Field on the New Java Class dialog, enter ECCustomUserMessagesKey, then click Finish. The file opens in the editor.
    5. Create a class similar to the following example:
      
        import java.util.*;
        import java.text.MessageFormat; 
      
        public interface ECSampleMessageKey {
      
          //Application message keys 
          public static String _ERR_TOOLS_TEST_USER_ERROR = "_ERR_TOOLS_TEST_USER_ERROR";
        }
      
    6. Save the file, but do not close the development environment.
  3. This procedure creates a new properties file, in a new folder, within the WebSphere Commerce development environment:
    1. In the WebSphere Commerce development environment, navigate to the WebSphereCommerceServerExtensionsLogic project.
    2. Navigate to the src folder, and then select the com.myCompany.messages folder.
    3. From the folder's pop-up menu, select New, and then Other.
    4. In the New dialog, click Simple, File, and then Next.
    5. In the File name field, type a unique name. For the purposes of this scenario, type UserMessagesNLS_locale.properties, where locale represents the locale from which your business users will access the WebSphere Commerce Accelerator.
    6. Click Finish to create the file and open it in an editor.
    7. To simplify future maintenance, it is a good idea to include comments in the new file. These comments are optional, though strongly recommended. At the top of this file, include some comments similar to the following to clarify the file's purpose:
      
          #
          # Customized messages
          ########################################################################
      
      _ERR_TOOLS_TEST_USER_ERROR=A Tools application error occurred.    
      
    8. Save the file, but do not close the development environment.
  4. Reference ECCustomUserMessages.TOOLS_TEST_USER_ERROR in your custom interface to send the message to the user.