Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Grails - getting a message value from controller

How can I get a value from message properties outside of GSPs? For instance, the equivalent of

<g:message code="some.message"/> 

but in a controller?

like image 711
armandino Avatar asked May 11 '10 22:05

armandino


1 Answers

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())   ... } 
like image 125
fabien7474 Avatar answered Sep 23 '22 01:09

fabien7474