Search code examples
stringgrailsnewlinegsp

Show multiline text in grails page


I'm going mad with this, I need to show a text I got from a textarea in grails 2.3.7 but when I replace \r\n characters for br/ and do an encodeAsHTML() I get the br's every where instead of new lines.

How is it done? this is what I've tried:

${cotizacionInstance.descripcion.encodeAsHTML().replaceAll('\r\n', '<br/>')}

${cotizacionInstance.descripcion.replaceAll('\r\n', '<br/>').encodeAsHTML()}

<%=cotizacionInstance.descripcion.replaceAll('\r\n', '<br/>').encodeAsHTML()%>

<%=cotizacionInstance.descripcion.encodeAsHTML().replaceAll('\r\n', '<br/>')%>

<%=cotizacionInstance.descripcion.replaceAll('\r\n', '<br/>').decodeHTML()%>

<%=cotizacionInstance.descripcion.decodeHTML().replaceAll('\r\n', '<br/>')%>

I don't like the way it comes out if I use the pre tag, because I loose all responsiveness.

I see that in the google chrome inspector I get my string between double quotes but I don't know how to remove those.

Thanks


Solution

  • There are factors left out of your description which make it impossible to say for sure but one way to get the behavior you are after is to mark the text as raw with something like this...

    ${raw(cotizacionInstance.descripcion.replaceAll('\r\n', '<br/>'))}
    

    I hope that helps.