Tutorials > Program model > Modify an existing controller command

< Previous | Next >


Create message information

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


Procedure

  1. Create the new properties file that will contain 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 | New | Other | General | File | Next

    2. In the File name field, enter MyNewErrorMessages.properties, then click Finish.

    3. Into the new file, copy the following text:

      _ERR_TOO_MANY_ITEMS=You cannot add more items into the shopping cart. Your shopping cart can hold up to five different items. 
      

    4. Save the changes.

  2. Create the Java code that references the properties file

    1. In WebSphere Commerce Developer, in the Enterprise Explorer view, navigate to Other Projects > WebSphereCommerceServerExtensionsLogic > src.

    2. From the src folder's pop-up menu, select New > Package. Enter the following information:

      1. In the Name field, enter com.ibm.commerce.sample.messages.

      2. Click Finish.

    3. From the com.ibm.commerce.sample.messages package's pop-up menu, 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 the changes.

    8. From the com.ibm.commerce.sample.messages package's pop-up menu, 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 the changes.

< Previous | Next >


+

Search Tips   |   Advanced Search