Announcement Announcement Module
Collapse
No announcement yet.
Exception while looking up key via messageSource Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • 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
    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?

    Comment


    • #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

      Comment


      • #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?

        Comment


        • #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

          Comment

          Working...
          X