Submit date parameter from html form to controller in thymeleaf

I ran into the issue below passing the date to the controller if I remove the date and then it works correctly.

My html code

<div class="form-group" id="all">
    <label class="col-lg-2 control-label" for="focusedInput3">Start date</label>
    <div class="col-lg-10">
        <input type="date" id="startDate" name="startDate" th:value="*{startDate}" />
<div class="form-group" id="all">
    <label class="col-lg-2 control-label" for="focusedInput4">End date</label>
    <div class="col-lg-10">
        <input type="date" id="endDate" name="endDate" th:value="*{endDate}" />


and my Entity class

@Column(name = "name")
private String courseName;

@Column(name = "semister")
private String semister;

@DateTimeFormat (pattern="dd-MMM-YYYY")
@Column(name = "startDate")
private Date startDate;

@DateTimeFormat (pattern="dd-MMM-YYYY")
@Column(name = "endDate")
private Date endDate;


after clicking the submit button, the following error appears:

enter image description here

Whitelabel Error Page

This application has no explicit mapping for /error, so you are seeing  this as a fallback.

Fri Apr 24 14:05:33 IST 2015
There was an unexpected error (type=Not Found, status=404).
No message available


Here is my controller

public class CourseScheduleController {

private CourseScheduleService courseScheduleService; 

public ModelAndView getAllativities() {
    Map<String, Object> model = new HashMap<String, Object>();
    model.put("courseName", "");
    model.put("semister", "");
    return new ModelAndView("createCourse",model);

public String saveCourseSchedule(@ModelAttribute CourseBE courseBE){
    return "redirect:/admin/createCourse";


Please help me to solve this problem.


source to share

3 answers

Perhaps you should include a binder in the controller:

    public void initBinder(WebDataBinder dataBinder) {

        dataBinder.registerCustomEditor(Date.class, new PropertyEditorSupport() {
            public void setAsText(String value) {
                try {
                    setValue(new SimpleDateFormat("dd/MM/yyyy").parse(value));
                } catch (ParseException e) {





Adding a binder to your controller will allow you to bind your form to your model.

 public void initDateBinder(final WebDataBinder binder) {
        binder.registerCustomEditor(Date.class, new CustomDateEditor(new SimpleDateFormat("yyyy-mm-dd"), true));


Should do the trick and convert your input string from your form to a date.

If you are using input type="date"

I guess you will have no choice in pattern date . If you want more flexibility in your template, just change the input type to text and adapt the format template to whatever you like.

You have to use th field in your html markup to bind to mork like:

<input th:field="*{startDate}"


and make sure your form has something like <form th:object="${courseBE}"

to define using a bean to bind your form.



Add the following:


To the properties file. This will help with verbose logging of HTTP errors.



All Articles