I\'ve stored a string in the database. When I save and retrieve the string and the result I\'m getting is as following:
This is my new object
Common problems have a variety of solutions
1> could be you that you replace \n with
so either in your controller/service or if you like in gsp:
${adviceInstance.advice?.replace('\n','
')}
2> display the content in a read-only textarea
${adviceInstance.advice}
3> Use the tag
${adviceInstance.advice}
4> Use css white-space http://www.w3schools.com/cssref/pr_text_white-space.asp:
//css code:
.space {
white-space:pre
}
Also make a note if you have a strict configuration for the storage of such fields that when you submit it via a form, there are additional elements I didn't delve into what it actually was, it may have actually be the return carriages or \r, anyhow explained in comments below. About the good rule to set a setter that trims the element each time it is received. i.e.:
Class Advice {
String advice
static constraints = {
advice(nullable:false, minSize:1, maxSize:255)
}
/*
* In this scenario with a a maxSize value, ensure you
* set your own setter to trim any hidden \r
* that may be posted back as part of the form request
* by end user. Trust me I got to know the hard way.
*/
void setAdvice(String adv) {
advice=adv.trim()
}
}