html tags.
Grails doesn't have a similar function to format Strings this way, but we can make our own Grail's codec, in order to obtain the same result as in PHP:
1. Create your own codec
2. Call it directly from the GSP page
1. To create the new codec, you just need to create a Grail's class in the folder grails-app/utils/ , like this:
NL2BRCodec.groovy (The file has to be named with the 'Codec' sufix)
class NL2BRCodec{
static encode = { string ->
string.trim().replaceAll("\n","<br>
")
}
}
That's all, now, from the GSP page, you just have to call the codec like this:
Or:
${object.stringValue.encodeAsNL2BR()}
changed this to:
ResponderEliminarstring?.trim().replaceAll('\n','<br />')
to make it fail-save and XML
otherwise: thank you for sharing this