jsp - Issue with kendo datepicker in Spring MVC -
i have form adding students. date of birth want use kendo ui datepicker, don't know how controller making binding model. if name attribute of date picker matches class element, following error: the request sent client syntactically incorrect.
if name attribute of date picker different, on save button clicked student inserted database, field date of birth being null. below content of jsp file, controller , student class. doing wrong?
jsp file
<div id="addstudent" class="space"> <div class="page-title">add student</div> <form:form commandname="addform" method="post"> <div class="editor-field"> <label for="firstname">first name</label> <input class="input k-popup k-list-container k-group k-reset" type="text" name="firstname" /> </div> <div class="editor-field"> <label for="lastname">last name</label> <input class="input k-popup k-list-container k-group k-reset" type="text" name="lastname" /> </div> <div class="editor-field"> <label for="dateofbirth">date of birth</label> <kendo:datepicker name="dateofbirth"></kendo:datepicker> //name attribute </div> <div class="editor-field left form-actions"> <a href="http://localhost:8080/gasfproject/gasf/main/menu/students" class="k-button">cancel</a> <input class="k-button" type="submit" name="add" value="save"> </div> </form:form> </div>
controller
@requestmapping(value = "/menu/addstudent", method = requestmethod.post) public string addstudent(@modelattribute("addform") student model) { logger.debug("received request in add student post"); // insert in database studentdatabaseaccess.addnewstudent(model); return "redirect:students"; }
student
public class student { private string firstname; private string lastname; private date dateofbirth; //getters , setters }
you can try adding datetimeformat annotation on dateofbirth field
public class student { private string firstname; private string lastname; @datetimeformat(pattern = "yyyy/mm/dd") private date dateofbirth; //getters , setters }
this tell spring how convert data date string , string date.
make sure pattern set in annotation same 1 set on kendo datepicker field in javascript.
Comments
Post a Comment