Java – error: trying to call method ‘format’ on an empty context object
Spring-boot v1. four point one
The following lines of code in my view:
<td th:each = "sprint : ${sprints}" th:text = "${sprint.releaseDate} ? ${#temporals.format(sprint.releaseDate,'MMM/dd/yyyy')}"></td>
My syntax is based on the S.O. problem springboot thymeleaf ordinal numbers. An error occurred:
However, if I run this line of code without thymeleaf format, it will work and render the localdate object table ("2016-05-25") in the default format
Question: why do I receive an 'empty context object' error? What does that mean? How do I edit to get the format I want?
Solution
To use #temporal objects, you need to include the thymeleaf - Extras - Java 8 time module in your project Here is the GitHub page of the extras module
In spring boot 1.4 In version 1, you only need to include the extras module. Automatic configuration will set it for you Make sure you provide the correct version, depending on your thymeleaf version:
I have the same spring boots and million dollar version as you, and I received the same error because I provided an inappropriate additional version (3.0.0) Switching it to a lower version fixed the problem (in my case, in the Maven POM file):
<dependency> <groupId>org.thymeleaf.extras</groupId> <artifactId>thymeleaf-extras-java8time</artifactId> <version>2.1.0.RELEASE</version> </dependency>