Add a new user message
If you want to incorporate user messages into your user interface elements, create the following assets:
- A class which contains the custom messages. WebSphere Commerce implements default messages in the ECToolsMessage class.
- 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.
- A property resource bundle which contains the translatable messages.
To create custom user messages:
- Create the message class:
- In the WebSphere Commerce development environment, navigate to the WebSphereCommerceServerExtensionsLogic project.
- Navigate to the src folder.
- From the src folder's pop-up menu, select New, and then Package.
- 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.
- Select the com.myCompany.messages folder.
- From the folder's pop-up menu, select New, and then Class.
- In the Name Field on the New Java Class dialog, enter ECCustomUserMessages, then click Finish. The file opens in the editor.
- Create a class similar to the following:
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); }- Save the file, but do not close the development environment.
- Create the class which maps the messages to their corresponding resource bundle keys:
- In the WebSphere Commerce development environment, navigate to the WebSphereCommerceServerExtensionsLogic project.
- Navigate to the src folder, and then select the com.myCompany.messages folder.
- From the folder's pop-up menu, select New, and then Interface.
- In the Name Field on the New Java Class dialog, enter ECCustomUserMessagesKey, then click Finish. The file opens in the editor.
- Create a class similar to the following:
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"; }- Save the file, but do not close the development environment.
- This procedure creates a new properties file, in a new folder, within the WebSphere Commerce development environment:
- In the WebSphere Commerce development environment, navigate to the WebSphereCommerceServerExtensionsLogic project.
- Navigate to the src folder, and then select the com.myCompany.messages folder.
- From the folder's pop-up menu, select New, and then Other.
- In the New dialog, click Simple, File, and then Next.
- 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.
- Click Finish to create the file and open it in an editor.
- 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.- Save the file, but do not close the development environment.
- Reference ECCustomUserMessages.TOOLS_TEST_USER_ERROR in your custom interface to send the message to the user.
Related concepts
Related tasks