开发者

How can I use g.message outside a Controller in Grails? [duplicate]

This question already has answers here: Closed 11 years ago.

Possible Duplicate:

Grails - getting a message value from 开发者_JS百科controller

I want to use a g.message() method inside a Service class, not a Controller. But I can't.

Code example:

// this is a method OUTSIDE a Controller 
def show = {
    def msg = message(code:"foo.bar") // I'm getting error here
}

It's possible to do this, or I have to use the old ResourceBundle class?


Another question have a perfect answer:

import org.springframework.context.i18n.LocaleContextHolder as LCH
...
class MyServiceOrMyDomain {
  def messageSource 
  ...
   messageSource.getMessage(key, ["myArg"].toArray(), LCH.getLocale())
  ...
}

Thanks to fabien7474

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜