简体   繁体   中英

How to set gsp element attribute value from controller

I have a field that can store data with html tags and format intact. For example: Field A has following data:

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>

Is it possible to display this field's value in GSP like this:

Field A:

Comment 1 by Saila 01/01/2014: Jhyap
Comment 2 by Kaila 2 01/05/2014: Momo kasto mitho
Comment 3 by Maila 3 01/05/2014: 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

${raw(htmlString)}

For more see Cross Site Scripting (XSS) Prevention

Instead of using the fieldValue tag you could just print out the value directly. Like this: ${Instance['Field A']} or maybe ${Instance.'Field A'} .

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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