Results 1 to 5 of 5

Thread: Exception while looking up key via messageSource

  1. #1
    Join Date
    Jan 2006
    Location
    South Africa, Cape Town
    Posts
    11

    Default 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

  2. #2

    Default

    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?

  3. #3
    Join Date
    Jan 2006
    Location
    South Africa, Cape Town
    Posts
    11

    Default

    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

  4. #4
    Join Date
    Feb 2007
    Posts
    16

    Default

    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

  5. #5
    Join Date
    Jan 2006
    Location
    South Africa, Cape Town
    Posts
    11

    Default

    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
  •