Grails – getting a message value from controller

Inside a controller or a taglib, you can use the following :

g.message(code: 'some.message')

However, inside domain classes or services, you need to inject messageSource and call getMessage() method from Sping class AbstractMessageSource.
This snippet shows you how to do that:

import org.springframework.context.i18n.LocaleContextHolder as LCH
...
class MyServiceOrMyDomain {
  def messageSource 
  ...
  messageSource.getMessage(code, msgArgs, defaultMsg, LCH.getLocale())
  ...
}

Leave a Comment

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)