When I add a date field on the jsp form I get this error, but it works fine without it.
Request
http://localhost:8080/myTasks/docreatetask?task=hi+there&description=stucked+here&date=2014-02-21&idTaskCategory=1&idTaskPriority=1&idTaskState=1&pending=1&idUser=0&idUser_responsible=0&evaluation=aaaaaa
Partly form.jsp
<form method="GET"
action="${pageContext.request.contextPath}/docreatetask">
<table>
<tr>
<td>Task</td>
<td><input name="task" type="text" /></td>
</tr>
<tr>
<td>Description</td>
<td><textarea name="description"></textarea></td>
</tr>
<tr>
<td>Date</td>
<td><input name="date" type="date"/></td>
</tr>
Partly Task.java component
@Component("task")
public class Task {
private long id;
private String task;
private String description;
private Date date;
private Date deadline;
private Category category;
private Priority priority;
private State state;
private User user;
private User userResponsible;
private String evaluation;
private Date timestamp;
private int pending;
Partly Task controller
@RequestMapping("/createtask")
public String createTask(Model model) {
List<Category> categories = taskService.getCategories();
List<Priority> priorities = taskService.getPriorities();
List<State> states = taskService.getStates();
List<User> users = taskService.getUsers();
model.addAttribute("categories",categories);
model.addAttribute("priorities",priorities);
model.addAttribute("states",states);
model.addAttribute("users",users);
return "createtask";
}
@RequestMapping(value="/docreatetask", method=RequestMethod.GET)
public String doCreateTask(Model model, Task task) {
System.out.println(">TaskController doCreateTask " + task);
return "taskcreated";
}
Any idea what this can be?
Thanks in advance!
New extra information about the error I added some validations annotations and I got new information about the error.
Field error in object 'task' on field 'date': rejected value [01/01/2001]; codes [typeMismatch.task.date,typeMismatch.date,typeMismatch.java.util.Date,typeMismatch]; arguments [org.springframework.context.support.DefaultMessageSourceResolvable: codes [task.date,date]; arguments []; default message [date]]; default message [Failed to convert property value of type 'java.lang.String' to required type 'java.util.Date' for property 'date'; nested exception is org.springframework.core.convert.ConversionFailedException: Failed to convert from type java.lang.String to type @org.springframework.format.annotation.DateTimeFormat java.util.Date for value '01/01/2001'; nested exception is java.lang.IllegalArgumentException: Unable to parse '01/01/2001']