简体   繁体   English

表单未在sql.date的控制器上赋予值

[英]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 表单未在sql.date控制器上赋予价值,我正在使用spring,以下是表单的代码

 <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 在印刷品上它为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" 而不是“ sql.date”使用“ util.date”

Also try by removing property "readonly" 也可以尝试删除属性“只读”

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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