简体   繁体   中英

Form is not giving value on controller for sql.date

Form is not giving value on controller for sql.date i am using spring and following is my code for form

 <form:input path="regDateFrom" cssClass="txt-field-date" id="txt_reg_form" readonly="true" />

and my controller is as.

 protected ModelAndView processFormSubmission(HttpServletRequest request,
        HttpServletResponse response, Object command, BindException errors)
        throws Exception {
    String param_error = null;
    VehicleSearch vehicleSampling = (VehicleSearch) command;
    System.out.println(vehicleSampling.getRegDateFrom());

on print it gives null

You need to have

@InitBinder
    public void initBinder(WebDataBinder binder) {
        SimpleDateFormat dateFormat = new SimpleDateFormat("dd-MM-yyyy");
        dateFormat.setLenient(false);
        binder.registerCustomEditor(Date.class, new CustomDateEditor(dateFormat, true));
    }

and instead of "sql.date" use "util.date"

Also try by removing property "readonly"

我猜您需要删除“ ReadOnly = true”,如果将readOnly设置为true,则该值将不会与请求一起传递。

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM