Announcement Announcement Module
Collapse
No announcement yet.
Error getting messageBundles from Controller Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • Error getting messageBundles from Controller

    Hi, I am trying get a message locale from Controller but I obtain this error:

    "org.springframework.web.util.NestedServletExceptio n: Request processing failed; nested exception is org.springframework.context.NoSuchMessageException : No message found under code 'error.alias' for locale 'es_ES'."

    In my Controller:

    Code:
    ApplicationContext context = MyContext.getApplicationContext();
            List errors = null;
    
            // Validar parametros        
            if (!Filter.onlyLetters(alias)) {
                errors.add(context.getMessage("error.alias", null, Locale.getDefault()));
            }
    MyContext.getApplicationContext() obtain spring context from MyApplicationContextAware that implements ApplicationContextAware.

    Code:
    public class MyContext {
    
        private static ApplicationContext context;
    
        public static void setApplicationContext(ApplicationContext applicationContext) {
            context = applicationContext;
        }
    
        public static ApplicationContext getApplicationContext() {
            return context;
        }
    }
    
    public class MyApplicationContextAware implements ApplicationContextAware {
    
        public void setApplicationContext(ApplicationContext ctx) throws BeansException {
            MyContext.setApplicationContext(ctx);
        }
    }
    Code:
    <bean id="myApplicationContextAware" class="...MyApplicationContextAware" />
    "error.alias" exist in messages.properties and messages_es_ES.properties.

    Code:
    /WEB-INF/classes/messages.properties
    /WEB-INF/classes/messages_es_ES.properties
    Code:
    <!-- Internacionalizacion -->
        <bean id="messageSource" class="org.springframework.context.support.ResourceBundleMessageSource">
        <property name="basename">
            <value>messages</value>
        </property>
    Any help?
Working...
X