Create message information

Your new command implementation uses a new error message: _ERR_TOO_MANY_ITEMS. In this step, you create the code for a new error message and its associated properties file.

About this task

Procedure

  1. Create the properties file that contains the message information:
    The properties file contains the text that displays in the web browser. Properties files facilitate translation, since the text is separated from the code, the file can be translated without affecting the Java code.
    1. In the Enterprise Explorer view, navigate to Stores > Java Resources > src.
    2. Right click the src folder, select New > Other.
    3. Select General > File and click Next.
    4. In the File name field, enter MyNewErrorMessages.properties, then click Finish.
    5. Copy the following text into the new file:
      _ERR_TOO_MANY_ITEMS=You cannot add more items into your shopping cart. Your shopping cart can hold up to five different items. 
      
    6. Save your changes.
  2. Create the Java code that references the properties file.
    1. In WebSphere Commerce Developer, in the Enterprise Explorer view, navigate to Utility Projects > WebSphereCommerceServerExtensionsLogic > src.
    2. Right click the src folder, select New > Package. Enter the following information:
      1. In the Name field, enter com.ibm.commerce.sample.messages.
      2. Click Finish.
    3. In Enterprise Explorer view, right click the com.ibm.commerce.sample.messages package, select New > Class.
    4. In the New Java Class wizard:
      1. In the Name field, enter MyNewMessages.
      2. Click Finish. The MyNewMessages class opens for editing.
    5. Within the class, add the following code:
      
      // Resource bundle used to extract the text for an exception
        static final String errorBundle = "MyNewErrorMessages";
      
        // An ECMessage describes an ECException and is passed
        // into the ECException when thrown
        public static final ECMessage _ERR_TOO_MANY_ITEMS =
            new ECMessage(ECMessageSeverity.ERROR, ECMessageType.USER, 
            MyNewMessageKeys._ERR_TOO_MANY_ITEMS, errorBundle);
      
    6. From the Source menu, select Organize Imports to add the following required import statements to the class:
      
      import com.ibm.commerce.ras.ECMessage;
      import com.ibm.commerce.ras.ECMessageSeverity;
      import com.ibm.commerce.ras.ECMessageType;
      
    7. Save your changes.
    8. Right click the com.ibm.commerce.sample.messages package, select New > Class.
    9. In the New Java Class wizard:
      1. In the Name field, enter MyNewMessageKeys.
      2. Click Finish.
    10. Replace the following default class implementation:
      
      public class MyNewMessageKeys {
      } 
      
      with the following code:
      public class MyNewMessageKeys {
      // This class defines the keys used to create new exceptions that are 
      // thrown by customized code.
        public static final String _ERR_TOO_MANY_ITEMS = "_ERR_TOO_MANY_ITEMS";
      }
      
    11. Save your changes.

Results