Spring provides a PropertyEditor named CustomDateEditor which you can configure to convert an empty String to a null value. You typically have to register it in a @InitBinder
method of your controller:
@InitBinder public void initBinder(WebDataBinder binder) {
SimpleDateFormat dateFormat = new SimpleDateFormat("dd/MM/yyyy
");
dateFormat.setLenient(false);
// true passed to CustomDateEditor constructor means convert empty String to null
binder.registerCustomEditor(Date.class, new CustomDateEditor(dateFormat, true));
}
Insert into the list the code:
<fmt:formatDate pattern="dd/MM/yyyy" value="${reg.dataCad}" var="dataCadFormat" />
${dataCadFormat}
Insert into the
form:
<form:input cssStyle="width:250px" maxlength="30" path="dataCad" size="30" />