Dlaczego po walidacji nie dostaje błędu w polu email? Mam adnotacje @NotEmpty i @Email
<form action="#" method="post" th:action="@{/register}" th:object="${user}">
<p th:if="${#fields.hasErrors('username')}" th:errors="*{username}" >error</p>
<p>Username: <input type="text" th:field="*{username}"/></p>
<p th:if="${#fields.hasErrors('password')}" th:errors="*{password}">error</p>
<p>Password: <input type="password" th:field="*{password}"/></p>
<p th:if="${#fields.hasErrors('userDetails.email')}" th:errors="*{userDetails.email}">error</p>
<p>Email: <input type="email" th:field="*{userDetails.email}"/></p>
<p>First Name: <input type="text" th:field="*{userDetails.firstName}"/></p>
<p>Last Name: <input type="text" th:field="*{userDetails.lastName}"/></p>
<br>
<input type="submit" value="Register">
</form>
@PostMapping("/register")
public String addNewUser(@Valid @ModelAttribute User user, BindingResult result) {
if (result.hasErrors()) {
List<ObjectError> errors = result.getAllErrors();
errors.forEach(err -> System.err.println("ERROR: " + err.getDefaultMessage()));
return "register";
} else {
return "home";
}
}
https://i.imgur.com/pz1GT2d.png