Sunday, May 22, 2011

No message found under code '...' for locale

This error can occur even if the code is in the resources file for example when rendering error pages resulting from Tomcat internal errors (500) like JSP errors. We better configure Spring to use the Reloadable Resource Message Source:
<bean id="messageSource"
         class="org.springframework.context.support.ReloadableResourceBundleMessageSource">
         <!--  <property name="basename" value="classpath:messages" />  -->
         <property name="basenames">
             <value>/WEB-INF/i18n/messages</value>
         </property> 
         <property name="cacheSeconds">
             <value>60</value>
         </property>
         <property name="fallbackToSystemLocale" value="false" />
     </bean>

JSP Spring Taglib for your error pages must contain a default value (not very i18n friendly) otherwise when the error pops up the JSP will fail with "No message found under code 'password' for locale 'en_US'"
<spring:message code="password" text="Password"/>

A special case for this issue is when Spring tries to parse an empty code. To avoid the issue in that case just define an empty code line in message.properties. Something like "=" or "=Empty" or "=Null" should do the trick.

8 comments:

  1. Hi,
    I get this error but i couldnt solve yet.



    my xml is like that.

    No message found under code 'menu_category_symgsm_label' for locale 'en'.

    Thanks..

    ReplyDelete
  2. Hi,
    I get this error but i couldnt solve yet.



    my xml is like that.

    No message found under code 'menu_category_symgsm_label' for locale 'en'.

    Thanks..

    ReplyDelete
  3. @Volkan, I see no XML in your post. Commonly this will mean you have no entry for the code in your messages bundle. I would try inserting the below line in a jsp:

    <spring:message code="menu_category_symgsm_label" text="Nothing"/>

    As it is not defined you will get "Nothing". Then change the code by something else that does show up and confirm the spring tag does work.

    Your error is related either to a missing code in the message bundle (commonly I use properties files and not XML) or by the spring trying to pull the bundle from a different location in your application.

    ReplyDelete
  4. is there a way to disable localization? i dont need it

    ReplyDelete
  5. Hi Nestor Urquiza,thanks for your response.
    When i add an entity via roo shell there is no problem. It works. But when i add second entity it says

    No message found under code 'menu_category_symuser_label' for locale 'en_US'.

    i am only typing roo shell commands inserting entity and fields.


    my log.roo

    persistence setup --provider HIBERNATE --database MYSQL
    entity --class ~.SymRole
    field string --fieldName roleName --notNull --sizeMax 50
    field number --fieldName roleValue --notNull --type java.lang.Integer
    controller all --package ~.controller
    entity --class ~.SymUser
    field string --fieldName userName --notNull --sizeMax 100
    field string --fieldName userSurname --notNull --sizeMax 100
    controller all --package ~.controller

    after first "controller all.." there is no problem.
    after second "controller all.." i am facing that problem.
    what am i doing wrong?

    Thank you.

    ReplyDelete
  6. Hi Nestor Urquiza,
    Thanks again. I solved my problem. When i format my computer i removed english keyboard input. Only keyboard input is in TR. I've add english input again and problem goes away :)
    But still i don't understand

    ReplyDelete
  7. I am sorry but being unfamiliar with Roo I cannot be of help I am afraid. I use really core Spring functionality (just what I need) in my custom Framework.

    ReplyDelete
  8. Thank you mate, I realised the resource bundle actually loads the path in full text.
    I had my message props under a folder called i18n and it wasn't loading them, changing the basename to i18n/message solved it.

    ReplyDelete