form
<input type="date" name="date" id="date" class="form-control" placeholder="Date">
controller
@PostMapping("/newtask")
public String newTask(@ModelAttribute("date") Date pickedDate, BindingResult result) {
if (result.hasErrors()) {
List<ObjectError> errors = result.getAllErrors();
errors.forEach(err -> System.out.println(err.getDefaultMessage()));
}
System.out.println(pickedDate + " controller");
return "redirect:/newtask";
}
@InitBinder
public void initBinder(WebDataBinder binder) {
binder.registerCustomEditor(Date.class,
new CustomDateEditor(new SimpleDateFormat("dd-MM-yyyy"), true));
}
Failed to convert property value of type 'java.lang.String' to required type 'int' for property 'date'; nested exception is java.lang.NumberFormatException: For input string: "2018-04-08"
A druga rzecz to zanim dodałem BindingResult to wywalało błąd Validation failed, dlaczego przy Date w ogole była walidacja?