I have a spring mvc web application that uses jquery. I used the spring tags to map the fields to pojo's directly. So that the date will get mapped to the corresponding field.
In Spring MVC a feild having date picker is reading date in correct format:
<script type="text/javascript">
$(document).ready(function () {
$("#deliveryDate").datepicker({
minDate: 0
});
});
$(document).ready(function () {
$("#quoationStartDate").datepicker({
minDate: 0
});
});
</script>
here is the input parameter on JSP:
<div class="col-md-6 col-sm-6">
<div class="form-group">
<i class="icon-calendar-7"></i>
<label>Actual Delivery On</label>
<form:input path="deliveryDate" class="form-control required" id="deliveryDate" name="deliveryDate" type="date" placeholder="dd-mm-yyyy" />
</div>
</div>
Have used @Initbinder to parse date
@InitBinder
public void dateBinder(WebDataBinder bind) {
System.out.println("In Binder");
SimpleDateFormat simpleDateFormat = new SimpleDateFormat("dd-mm-yyyy");
simpleDateFormat.setLenient(false);
bind.registerCustomEditor(Date.class, new CustomDateEditor(simpleDateFormat, true));
}
But after a form post operation the date received in the controller has value null. What must be the solution to this so that I will receive a date in format dd-MM-yyyy and this date can be stored into database.