Problem:
I'm trying to get a LocalDateTime of this input within a @Controller
using a <form>
that uses Thymeleaf.
<input class="form-control" id="dueDate" type="datetime-local" th:field="*{dueDate}"/>
But it always returns null
, the other fields are working perfectly.
Object used to transfer data:
public class TaskDTO {
private long id;
@Size(min=8)
@NotNull
private String name;
@Size(min=8)
@NotNull
private String description;
@NotNull
private String priority;
@Size(min=8)
@NotNull
private String location;
private boolean completed;
@DateTimeFormat(pattern = "dd-MM-yyyy HH:mm")
@NotNull
private LocalDateTime dueDate;
//getters e setters omitidos
}
I think it's not as relevant, but this is the controller:
@PostMapping("/dashboard/task/{id}")
public String TaskForm(@Valid @ModelAttribute("taskDTO")TaskDTO taskDTO,BindingResult bidingResult,@PathVariable("id")long id) {
if(bidingResult.hasFieldErrors()) {
//
}
Project p = projectRepository.findById(id).get();
Task t = taskDTO.generateTask(p);
taskRepository.save(t);
return "main";
}