Grails - pobieranie wartości wiadomości z kontrolera
Jak mogę uzyskać wartość z właściwości wiadomości spoza GSPs? Na przykład odpowiednik
<g:message code="some.message"/>
Ale w kontrolerze? 29
2 answers
Wewnątrz kontrolera lub taglib, możesz użyć:
g.message(code: 'some.message')
Jednak wewnątrz klas lub usług domeny, musisz wprowadzić messageSource i wywołać metodę getMessage() z klasy Sping AbstractMessageSource. Ten fragment pokazuje jak to zrobić:
import org.springframework.context.i18n.LocaleContextHolder as LCH
...
class MyServiceOrMyDomain {
def messageSource
...
messageSource.getMessage(code, msgArgs, defaultMsg, LCH.getLocale())
...
}
47
Author: fabien7474,
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/doraprojects.net/template/agent.layouts/content.php on line 54
2010-05-11 23:24:40
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/doraprojects.net/template/agent.layouts/content.php on line 54
2010-05-11 23:24:40
Możesz również zaimportować lib znacznika walidacji i użyć go, aby pobrać źródło wiadomości.
import org.codehaus.groovy.grails.plugins.web.taglib.ValidationTagLib
def g = new ValidationTagLib()
g.message(error: error)
11
Author: Blacktiger,
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/doraprojects.net/template/agent.layouts/content.php on line 54
2010-05-12 13:55:11
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/doraprojects.net/template/agent.layouts/content.php on line 54
2010-05-12 13:55:11