• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Liutauras Vilda
  • Bear Bibeault
  • Jeanne Boyarsky
  • paul wheaton
Sheriffs:
  • Junilu Lacar
  • Paul Clapham
  • Knute Snortum
Saloon Keepers:
  • Stephan van Hulst
  • Ron McLeod
  • Tim Moores
  • salvin francis
  • Carey Brown
Bartenders:
  • Tim Holloway
  • Frits Walraven
  • Vijitha Kumara

Formating errormessage in thymeleaf template  RSS feed

 
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi All
This is my first post on this forum, so don't shoot me if I posted in the wrong topic.
I have a springboot MVC app, which has a registerform, when there is wrong input from the user the controller add's an error message to the model which is then shown on the bottom of the page.
Everything is working fine, but for some reasson my message is concatenated all together.
I tried "\n", System.lineSeparator() and even knowing html is not redered, I also tried <br>, non of these worked.
When I print the errormessage to the console it's formatted corectly, so the prob is in my template.
I use a StringBuilder tobuild the message and then call the toString method when passing it to the model.
Anyone an idea how to solve my issue?
 
Sheriff
Posts: 21689
101
Chrome Eclipse IDE Java Spring Ubuntu VI Editor Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Welcome to the Ranch!

Can you show the part of your Thymeleaf template where you render this error?
 
Pieter Vandevelde
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
 
Pieter Vandevelde
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
an example of something being appende to the errormessage:

the ("\r\n") is the last thing I tried, I tried them separetly too, aswell as <br> and the System.lineSeperator()
 
Sheriff
Posts: 24290
55
Eclipse IDE Firefox Browser MySQL Database
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I found a Thymeleaf tutorial online and poked around in it for a few minutes. Looks like your answer is here: Unescaped Text.
 
Rob Spoor
Sheriff
Posts: 21689
101
Chrome Eclipse IDE Java Spring Ubuntu VI Editor Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I think Paul is right. Thymeleaf escapes your input when you use th:text. Note that whitespace like line breaks don't matter because in HTML these show up as a single space. The <br> tag is the way to go as long as you tell Thymeleaf not to escape it.
 
I carry this gun in case a vending machine doesn't give me my fritos. This gun and this tiny ad:
global solutions you can do in your home or backyard
https://coderanch.com/t/708587/global-solutions-home-backyard
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!