Adding a custom user or error message to a BOD service module
Adding custom messages to your BOD framework commands involves creating your properties file with a specified naming convention and location. The logging framework is configured to traverse up the package hierarchy and find and load any resource bundles (properties files) with names matching the naming convention.
Procedure
- Create a properties file to list the message values, for each locale
that you wish to support:
- The property file should be located in the
com.mycompany.logging.properties
package wheremycompany
is your company name or some other, arbitrary unique identifier. The most important thing is that the package name ends withlogging.properties
and that this package can be found at or above the calling class in the package hierarchy. - The name of the property files must follow the pattern below:
WcMyServiceModuleMessages_locale.properties
, where MyServiceModule is the name of your service module and locale is the locale identifier (for example,en_US
).
# translateable messages for the MyServiceModule component # Message keys are defined in the class # com.mycompany.logging.MyServiceModuleMessageKeys MYCO0001E= MYCO0001E: The value "{1}" is invalid for parameter name "{0}" MYCO0002I= MYCO0002I: The value {0} is over 9000!
- The property file should be located in the
- Create a message key class which captures the property file keys.
This class must define a static instance variable for each of the message
keys defined in your property file.
- Log your error as follows:
Logger logger = LoggingHelper.getLogger(MyClass.class); logger.logp(Level.SEVERE, "MyClass","MyMethod", MyServiceModuleMessageKeys.MYCOMPANY_MYCOMMAND_INVALID_PARAMETER, new Object[] {parameterName, parameterValue} );