0

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!

kosh
  • 115
  • 8

2 Answers2

3

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

cfrick
  • 35,203
  • 6
  • 56
  • 68
ABC
  • 4,263
  • 10
  • 45
  • 72
  • Thank you Abdullah! Any insights on what to do if our grails app version is 2.2.5 since this method is only available since 2.3? – kosh Dec 16 '14 at 11:07
  • To disable HTML encoding for one expression,use <%=expression%> notation instead of ${} for version <2.3 for further reference you can see http://stackoverflow.com/questions/1337464/overriding-grails-views-default-codec-html-config-back-to-none – ABC Dec 16 '14 at 11:33
0

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

David
  • 1,940
  • 3
  • 17
  • 30