Announcement Announcement Module
Collapse
No announcement yet.
@InitBinder problem - Date problem Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • @InitBinder problem - Date problem

    Hi,

    I have a form on the JSP page. One field is the date of birth, where the date is selected using jquery datepicker.Problem is that for example if in the form is selected date 24.6.1979. When I do debugging in the code I have date 24.1.1979 not 24.6.1979. Actually always in the code I get a January .Does anyone know why? can someone help me? below is my code. Thanks.

    JSP
    <script>
    $(function() {
    $( "#datepicker" ).datepicker({dateFormat: "dd/mm/yy",changeYear: true});
    });
    </script>

    <tr>
    <td>Date of birth :</td>
    <td><form:input path="dob" id="datepicker" /></td>
    <td><form:errors path="dob" cssClass="error" /></td>

    </tr>



    MODEL ChangeForm.java
    @NotNull
    @DateTimeFormat(pattern="dd/mm/yy")
    private Date dob;




    CONTROLLER
    @InitBinder
    public void initBinder(WebDataBinder binder) {
    binder.initDirectFieldAccess();

    SimpleDateFormat dateFormat = new SimpleDateFormat("dd/mm/yy");
    dateFormat.setLenient(false);
    binder.registerCustomEditor(Date.class, new CustomDateEditor(dateFormat, false));
    }


    @Override
    @RequestMapping(value = "/userChange", method = RequestMethod.POST)
    public String changeUser(@ModelAttribute("changeForm") @Valid ChangeForm changeForm, BindingResult result, HttpServletRequest request) {



    cfv.validate(changeForm, result);



    if (result.hasErrors()) {

    return "userDataEdit";

    }
    else {

    userDataService.changeUser(changeForm);




    return "redirect:/userData";

    }

  • #2
    Please use [ code][/code ] tags when posting code, that way it remains readable ...

    Check your dateformat dd/mm/yy is not what you expect it to be... (Hint m != M, check the javadocs in the link above).

    Comment

    Working...
    X