Search code examples
htmlspring-bootutf-8thymeleafproperties-file

thymeleaf error message with converted special characters


for my web app (spring boot + thymeleaf) i use message_fr.properties file witch contains some special characters converted to html the problem comes when i display the error validation message in lang=fr :

<span th:if="${#fields.hasErrors('title')}" th:errors="*{title}"></span>

assume that key/value are : NotEmpty.item.title = Ne doit pas &ecirc;tre null on screen it displays the error message without conversion : Ne doit pas &ecirc;tre null

how can i resolve it ?


Solution

  • th:errors will escape HTML in the same way that th:text does. Before 3.0.8, you would have to iterate over the errors like this:

    <span th:if="${#fields.hasErrors('title')}" th:each="err : ${#fields.errors('title')}"></span>
    

    However, post 3.0.8, Thymeleaf-Spring includes th:uerrors for unescaped error messages to the same effect:

    <span th:uerrors="*{title}"></span>