简体   繁体   English

如何从控制器设置gsp元素属性值

[英]How to set gsp element attribute value from controller

I have a field that can store data with html tags and format intact. 我有一个字段可以存储带有html标签和完整格式的数据。 For example: Field A has following data: 例如:字段A具有以下数据:

Comment 1 by User 1 01/01/2014: Jhyap 
<br> 
Comment 2 by User 2 01/05/2014: Momo kasto mitho
<br>
Comment 3 by User 3 01/05/2014: Launa k garney aba

Currently on using <g:fieldValue bean="${Instance}" field="Field A"/> the gsp displays field as Comment 1 by Saila 01/01/2014: Jhyap<br>Comment 2 by Kaila 2 01/05/2014: Momo kasto mitho<br>Comment 2 by Kaila 2 01/05/2014: Momo kasto mitho<br> 当前正在使用<g:fieldValue bean="${Instance}" field="Field A"/> ,gsp将字段显示为Comment 1 by Saila 01/01/2014: Jhyap<br>Comment 2 by Kaila 2 01/05/2014: Momo kasto mitho<br>Comment 2 by Kaila 2 01/05/2014: Momo kasto mitho<br>

Is it possible to display this field's value in GSP like this: 是否可以像这样在GSP中显示此字段的值:

Field A: 栏位A:

Comment 1 by Saila 01/01/2014: Jhyap Saila的评论1(2014年1月1日):Jhyap
Comment 2 by Kaila 2 01/05/2014: Momo kasto mitho 评论2由Kaila 2 01/05/2014:Momo kasto mitho
Comment 3 by Maila 3 01/05/2014: Launa k garney aba Maila 3评论3,2014年1月5日:Launa k garney aba

Thanks for your time! 谢谢你的时间!

For the sake of avoiding Cross Site Scripting (XSS) Grails escape all the html content in ${} expression in GSPs, therefore you can use 为了避免跨站点脚本(XSS), Grails会在GSP中转义${}表达式中的所有html内容,因此可以使用

${raw(htmlString)}

For more see Cross Site Scripting (XSS) Prevention 有关更多信息,请参见跨站点脚本(XSS)预防

Instead of using the fieldValue tag you could just print out the value directly. 除了使用fieldValue标记外,您还可以直接打印出该值。 Like this: ${Instance['Field A']} or maybe ${Instance.'Field A'} . 像这样: ${Instance['Field A']}${Instance.'Field A'}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM