-
Dec 23rd, 2008, 08:43 AM
#1
Exception while looking up key via messageSource
Hi
I need to translate some text in my domain objects (for specific reports) and want to use the spring-defined language properties files.
I created a new class ResourceManager for this. In the domain object I use then "String firstNameLabel = resourceManager.translate("FirstName");"
I use org.springframework.context.support.ResourceBundle MessageSource which works great for my JSPs with spring:message. Neverthelss messageSource.getMessage(..) throws allways the following exception:
Caused by: org.springframework.context.NoSuchMessageException : No message found under code 'AutoEmailReports' for locale 'en_ZA'.
at org.springframework.context.support.DelegatingMess ageSource.getMessage(DelegatingMessageSource.java: 65)
Why does it work in a JSP and not in my objects?
--------------------------------------------------------
public class ResourceManager implements MessageSourceAware {
private MessageSource messageSource;
public ResourceManager(){
}
public void setMessageSource(MessageSource messageSource){
this.messageSource = messageSource;
}
public String translate(String key){
return this.messageSource.getMessage(key, null, LocaleContextHolder.getLocale());
}
}
--------------------------------------------------------
Any help is greatly appreciated.
Regards
Daniel Putra
-
Dec 23rd, 2008, 11:25 AM
#2
Need some additional info: you have FirstName as the translation but your error says AutoEmailReports. If that is NOT a typo, your error should be obvious.
Are you sure your resource files are properly hooked up? Where do they exist in your project?
-
Dec 23rd, 2008, 04:01 PM
#3
Hi Jonnio
Thanks for your reply. Sorry about the typo, just tried to replace my key variable with some meaningful string.
My property files are all in WEB-INF\classes\languageresources and this works fine in my JSPs which means that Spring loads them properly. As I also do not get a NullPointerException but a NoSuchMessageException my messageSource setter is working fine. So what could the problem be?
Regards
Daniel
-
Dec 26th, 2008, 01:36 PM
#4
Hi,
The exception from Spring :
No message found under code 'AutoEmailReports' for locale 'en_ZA'.
Do you actually have the file under the *en_ZA postix under classes directory?
Alan Mehio
London, UK
-
Dec 27th, 2008, 05:13 AM
#5
Hi Allan
If it cannot be resolved then the core "messages.properties" file or any other valid resource bundle is used automatically. Nevetheless this works fine in my JSPs which means that the keys can be resolved.
So what else could be the problem?
Best regards
Daniel
Tags for this Thread
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules