Moved from SourceForge
http://sourceforge.net/tracker/index.php?func=detail&aid=1122348&group_id=48726&atid=453974:
There is a problem when you are not using
"org.apache.struts.util.PropertyMessageResouces" but a
subclass of this (the default implementation was not
acurate for my strtus proyect ;-( ).
Cause there is a hard-coded check agains class name, I
can't get the key resolved for my menu messages.
Better than check for class name (and to avoid need for
struts library) is to check for method signature existence.
You can do this whith this code (replace in the correct
part):
// this is here to prevent a non-struts webapp from
throwing a NoClassDefFoundError
boolean instanceOfMessageResources = true;
Method method_complete = null;
Method method = null;
try {
Class clazz = messages.getClass();
method_complete = clazz.getMethod("getMessage", new
Class[] {Locale.class, String.class});
method = clazz.getMethod("getMessage", new Class[]
{String.class});
} catch (NoSuchMethodException e) {
instanceOfMessageResources = false;
}
if (instanceOfMessageResources) {
MessageResources resources = (MessageResources) messages;
try {
if (locale != null) {
//Method method = clazz.getMethod("getMessage", new
Class[] {Locale.class, String.class});
message = (String)method_complete.invoke(messages,
new Object[] {locale, key});
} else {
message = (String)method.invoke(messages, new
Object[] {key});
}
} catch (Throwable t) {
message = null;
}
}