0
Problem :
I am trying to receive a Localdatetime of this input within a @Controller
using a <form>
using the Thymeleaf.
<input class="form-control" id="dueDate" type="datetime-local" th:field="*{dueDate}"/>
But 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 so 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";
}
I had already added and configured this dependency, finally I passed a string and converted it to the server.
– E.ss