Thymeleaf does not display date in HTML5 component

0

Hello! I'm starting to study thymeleaf next to Spring MVC and I came across a problem I can not solve.

I have a date field with the type="date" component of HTML5 in a form, which works 100% when registering. However, when I use the form for editing, all form data is displayed in its HTML components, minus the date.

When analyzing the HTML source of the page the date is there, but it does not appear in the visual component.

<input type="date" class="form-control" id="data" name="data" value="03/03/1985">

When I use JSP / JSTL whenever the form opens for editing, the date in the HTML5 component already appears in the input, but it is not appearing with Thyemeleaf.

Does anyone know the reason and how to solve it? This is my input:

<input th:field="*{data}" type="date" class="form-control" />
    
asked by anonymous 02.08.2017 / 20:26

1 answer

0

I found the problem. I had created a Formatter type class to format the date and it looks like that was the problem. When I created this class I removed the @DateTimeFormat annotation from the LocalDate attribute. I ended up removing the Formatter class and returning with the annotation quoted. And to format the date on the page, I used the dependency

<dependency>
  <groupId>org.thymeleaf.extras</groupId>
  <artifactId>thymeleaf-extras-java8time</artifactId>
  <version>3.0.0.RELEASE</version>
</dependency>

I registered it in the Template Engine configuration

templateEngine.addDialect(new Java8TimeDialect());

and at the time of displaying date formatted on the page

<td th:text="${#temporals.format(user.data, 'dd MMM yyyy')}"></td>

In this way I was able to format the date to display on the page and also the date issue in the date field of the input.

    
02.08.2017 / 20:58