A user writes in to ask:
When providing an overridden message bundle, is it somehow possible to capture the name of the attribute and utilize this when customizing the error messages?
The answer is, "sure." The details are highlighted in the Customizing Error Messages topic in the online help, but in a nutshell what you can do is to extract the source code for the CSMessageBundle.java from the ./BC4J/src/bc4j-messages.zip file that ships with JDeveloper 10g and search for the BC4J error code. For example, searching for the error code 27014, you'll find the line in the file like this:
public static final String EXC_VAL_ATTR_MANDATORY = "27014";
Then, take this string constant name EXC_VAL_ATTR_MANDATORY and search for it in the file to find the actual default error message string. You'll find the line:
{EXC_VAL_ATTR_MANDATORY, "Attribute {2} in {1} is required"},
The numeric placeholders like {2} and {1} represent the standard way in the java.text.MessageFormat class to refer to the values of the optional Object-array of detail information that can be supplied with a message being formatted. You can use those same placeholders in your own custom message string.
If you're curious to find out what all the available detail error parameters might be for a given error message, you can provide a temporary, overridden error message in your customized error message bundle like:
{CSMessageBundle.EXC_VAL_ATTR_MANDATORY, "0={0}, 1={1}, 2={2}, 3={3}, 4={4}"}
and then use the Business Components tester tool (or your own application if that is easier) to make the exception get raised. In the case of a mandatory attribute not being provided, with your temporary error message you'll see something like:
JBO-27014: 0=Entity Object, 1=Dept, 2=Dname, 3={3}, 4={4}
so you would know that there were three pieces of available detail information for this particular exception, and you can decide which ones (if any) make sense to be used in your actual customized error message.
2:02:43 PM
|