I saw something as below for form validation using Thymeleaf and Spring boot.
<p th:if="${#fields.hasErrors('datePlanted')}" th:errors="*{datePlanted}">Incorrect date</p>
Now I don't understand: where is this field object coming from? Is this something that Spring prepares? I am lost somewhere here.
Fields.java
is a class presented in package org.thymeleaf.spring4.expression.Fields
It's pulled in by thymeleaf-spring4-xxx.jar
#fields.hasErrors
is syntax to call method hasErrors()
of Fields
class.
public boolean hasErrors(final String field) {
return FieldUtils.hasErrors(this.configuration, this.processingContext, field);
}