I created a basic multi-line input form using the Spring web app in Intellij. The form successfully saves the backend when using strings only, so I decided to add a date field to the model and tried to change the / jsp controller to accept this in the input form (and display it in the list of entries). I am having problems with an input form that does not receive a value.
Entity:
@Temporal(TemporalType.DATE)
@DateTimeFormat(pattern="dd.MM.yyyy")
private Date dueDate;
public Date getDueDate() {
return dueDate;
}
public void setDueDate(Date dueDate) {
this.dueDate = dueDate;
}
JSP (I assume the value should be empty here, since I start by filling in an empty field?):
<div class="control-group">
<form:label cssClass="control-label" path="dueDate">Due Date:</form:label>
<div class="controls">
<input type="text" path="dueDate" class= "date" name = "dueDate" value = "<fmt:formatDate value="" pattern="MM-dd-yyyy" />"/>
</div>
</div>
Controller:
@RequestMapping(value = "/todos/add", method = RequestMethod.POST)
public String addUser(@ModelAttribute("todo") Todo todo, BindingResult result) {
System.err.println("Title:"+todo.getTitle());
System.err.println("Due Date:"+todo.getDueDate());
todoRepository.save(todo);
return "redirect:/todos/";
}
My debug file shows the runtime: null, so nothing is sent for my date field from the form when posting. This means that the date field is never saved, and then the repository is saved.