Reputation: 9206
How to resolve spring 400 error.
My controller:
@InitBinder
protected void initBinder(WebDataBinder binder) {
SimpleDateFormat dateFormat = new SimpleDateFormat("dd/MM/yyyy");
binder.registerCustomEditor(Date.class, new CustomDateEditor(
dateFormat, false));
}
@RequestMapping(value = "/admin/users/edit", method = RequestMethod.POST)
public ModelAndView editUser(final @ModelAttribute AdminForm form,
Principal principal)
public class AdminForm {
...
User newUser;
public User getNewUser() { return newUser; }
public void setNewUser(User newUser) { this.newUser = newUser; }
...
}
public class User {
...
@DateTimeFormat(pattern = "dd/MM/yyyy")
Date birthDate;
...
}
JSP file has this input box:
<form:input
class="tcal"
name="date"
itemLabel="date"
path="newUser.birthDate"/>
Browser generates this POST request:
newUser.fio=%D0%9F%D0%B5%D1%82%D1%80%D0%BE%D0%B2+%D0%A1%D0%B8%D0%B4%D0%BE%D1%80+%D0%9F%D0%BE%D0%BB%D0%B8%D0%BA%D0%B0%D1%80%D0%BF%D0%BE%D0%B2%D0%B8%D1%87&newUser.login=das&newUser.password=8904&newUser.birthDate=08%2F04%2F2014&newUser.id=23
You can see that there are also other fields fio, login, password and id. If I remove birthDate, then 400 error goes away, but I need this parameter.
How can I avoid this problem?
Thanx
Upvotes: 1
Views: 952
Reputation: 9206
My problem was that in one place there was java.sql.Date and java.util.Date in another. When I changed both to java.util.Date, it worked.
Upvotes: 2