Input type="date" thymeleaf
Taking a look at the comment with the error log it seems to be a conversion problem between String
to java.util.Date
. After searching for a while in the Thymeleaf GitHub I saw two issues which can explain how to proceed in this case:
- Discussion of the conversion including date in this issue.
- Implementation of the conversion is explained here.
From the last point, I added an annotation to the start date of your project class:
// This is "org.springframework.format.annotation.DateTimeFormat"
@DateTimeFormat(pattern = "yyyy-MM-dd")
private Date start;
And after that, I was able to receive the date in your controller POST method.
Take into account you also need to change your th:value
and th:field
attributes from your template for the date value from ${project.start}
to *{start}
, as I wrote in the comments, as you did for the name
and description
fields.
Use String instead of Date:
@DateTimeFormat(pattern = "yyyy-MM-dd")
private String fromDate;