Thymeleaf + Spring MVC - selected date field on HTML5 is null on controller -
the following input field date object works, apparently, nicely. when reaches controller, value executiondate
null.
<form role="form" action="#" th:object="${pojo}" th:action="@{/scheduler/create}" method="post"> <div class="col-lg-5 col-sm-5 col-xs-10" > <div class="well with-header"> <div class="header"> <label th:for="datepicker0">execution date: </label> </div> <div class="form-group input-group"> <input id="datepicker0" type="text" name="executiondate" th:field="*{executiondate}" class="form-control"></input> <span class="input-group-addon"><i class="fa fa-calendar"></i></span> </div> </div> </div> // rest of page </form>
relevant part of controller is:
@requestmapping(value = "/scheduler/create", method = requestmethod.post) public string createschedulerpost(@valid @modelattribute("pojo") schedulerpojo pojo, bindingresult result, modelmap model) { system.out.println(pojo.getdescription()); system.out.println(pojo.isrecurrent()); system.out.println(pojo.getexecutiondate()); system.out.println(pojo.getstartdate()); system.out.println(pojo.getterminationdate()); system.out.println(pojo.getfailstrategy()); (...) // i'm verifying whether schedulerpojo pojo object has values now... }
the schedulerpojo dto is:
public class schedulerpojo { private string id; private string description; private date executiondate; private boolean recurrent; private date startdate; private date terminationdate; private schedulerfailstrategy failstrategy; // other attributes, getters , setters }
other, fields description string , recurrent boolean checkbox inputs return given value on html.
what missing here?
according thymeleaf+spring tutorial th:field
generates code same set id
, name
tags:
<input type="text" th:field="*{dateplanted}" />
equivalent code :
<input type="text" id="dateplanted" name="dateplanted" th:value="*{dateplanted}" />
maybe need remove id=datepicker0
executiondate
, bind class
on datepicker?
<input class="date" type="text" th:field="*{executiondate}" class="form-control"></input> ... <script> $(document).ready(function () { $('.date').datepicker({dateformat: 'dd.mm.yy'}); }); </script>
Comments
Post a Comment