History | Log In     View a printable version of the current page.  
Issue Details (XML | Word | Printable)

Key: SM-34
Type: Improvement Improvement
Status: Open Open
Priority: Major Major
Assignee: Matt Raible
Reporter: Matt Raible
Votes: 0
Watchers: 0
Operations

If you were logged in you would be able to see more operations.
Struts Menu

MessageResourcesMenuDisplayer.getMessage(String key) fix

Created: 09/May/06 02:05 AM   Updated: 09/May/06 02:37 AM
Component/s: Menu Core
Affects Version/s: 2.3
Fix Version/s: 2.5


 Description  « Hide
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;
}
}

 All   Comments   Change History   FishEye      Sort Order: