Unexplained Issue with working with ActionMessages.
All,
BACKGROUND:
I have a simple Struts application that is connected to MySQL. In one of my Actions that calls a method that accesses the database, I'm handling the SQLExceptions by catching the exception and storing (as strings) the error code and message into two bean properties (both properties have the appropriate getter/setter methods) and the bean is passed back to my "calling" action:
...catch (SQLException ex) {
beanname.setCaughterror(Integer.toString(ex.getErrorCode()));
beanname.setCaughterrormessage(ex.getMessage());
....
return beanname;
}
Now, I can create a scenario where I create a SQL Exception by inserting a record that duplicates the primary key. This creates the exception code 1062 (Duplicate Primary Key error) in MySQL.
Once back in the action code, I now have a bean with the error code and message. I then add these two pieces of information to the Action Messages object with the following code:
ActionMessages messages = new ActionMessages();
messages = MyExceptionHandler.handleMyErrors(messages,beanname.getCaughterror(),beanname.getCaughterrormessage());
saveErrors(request, messages);
Now the MyExceptionHandler.handleMyErrors looks like this:
public static ActionMessages handleMyErrors (ActionMessages messages,
String errorcode,
String myerrormessage) {
.....
if (errorcode.equals("1062")) {
messages.add("myerrortext", new ActionMessage("myerrortext", myerrormessage));
}
return messages;
....
}
My ApplicationResources file looks like this:
....
myerrortext= The system generated error message is noted below:
{0}
....
ISSUE:
The error message prints out correctly; however, at any point in time, whenever I try and print the error message itself, (either by displaying the bean property value in my JSP page via ${beanname.caughterrormessage} or by saving it to a string String ttest = beanname.getCaughtErrorMessage()) it comes up null. Can anyone explain why that is happening this way? I can't for the life of me figure out why it displays in the ErrorMessage, but it appears to be null if accessed directly.
Please Help.

