admin管理员组文章数量:1419633
I am new in grails and trying to set value from messages.property (i18n) in g:set tag on gsp and then use it in java script on the same gsp page. For example:
my messages.property should look like: operation.hello=Hello '{0}'
in the gsp there should be:
<g:set var="foo" value="${operation.hello('Patty')}" scope="page"/>
and
<g:javascript>
alert( $foo )
</g:javascript>
not sure how to handle this.Can anyone help?
our basic intention is to use a parametrized-messages.property value from javascript.
Tried JAWR plug-in and that worked well but JAWR had other issues that we do not want in our case
I am new in grails and trying to set value from messages.property (i18n) in g:set tag on gsp and then use it in java script on the same gsp page. For example:
my messages.property should look like: operation.hello=Hello '{0}'
in the gsp there should be:
<g:set var="foo" value="${operation.hello('Patty')}" scope="page"/>
and
<g:javascript>
alert( $foo )
</g:javascript>
not sure how to handle this.Can anyone help?
our basic intention is to use a parametrized-messages.property value from javascript.
Tried JAWR plug-in and that worked well but JAWR had other issues that we do not want in our case
Share Improve this question edited Aug 22, 2012 at 22:44 Gregg 35.9k22 gold badges114 silver badges221 bronze badges asked Aug 22, 2012 at 22:22 VictorGramVictorGram 2,66111 gold badges56 silver badges90 bronze badges3 Answers
Reset to default 3So long as you understand that all this is pocessed on the server side, I think all you need to do is use the correct syntax:
<g:set var="foo" value="${g.message(code: 'operation.hello', args: ['Patty'])}" scope="page"/>
<g:javascript>
alert( "${foo}" );
</g:javascript>
By the time this reaches the browser, it should simply read:
<script type="text/javascript">
alert( "Hello Patty" );
</script>
If I got what you mean, basically you can't.
G tags are server side stuff. Their value args must be present while the g tags are rendered, you cannot pass a javascript (client side) value to g tag (which basically it's a server side snippet). You can put the result of a g tag into a javascript string, not the opposite.
Does this answer your question?
<script type="text/javascript">
var helloTo = "Patty";
var message = "${g.message(code: 'operation.hello', args: ["+ helloTo + "])}";
</script>
本文标签: grailsHow to call messagesproperty (parametrized) value from javascript on a gsp pageStack Overflow
版权声明:本文标题:grails - How to call messages.property (parametrized) value from javascript on a gsp page - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1745314571a2653090.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论