• 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
  • Devaka Cooray
  • Jeanne Boyarsky
  • Bear Bibeault
Sheriffs:
  • Junilu Lacar
  • Paul Clapham
  • Knute Snortum
Saloon Keepers:
  • Ron McLeod
  • Tim Moores
  • Stephan van Hulst
  • salvin francis
  • Carey Brown
Bartenders:
  • Tim Holloway
  • Frits Walraven
  • Ganesh Patekar

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: 21602
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: 24080
54
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: 21602
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.
 
All of the world's problems can be solved in a garden - Geoff Lawton. Tiny ad:
RavenDB is an Open Source NoSQL Database that’s fully transactional (ACID) across your database
https://coderanch.com/t/704633/RavenDB-Open-Source-NoSQL-Database
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!