【问题标题】:Form is not giving value on controller for sql.date表单没有为 sql.date 的控制器提供价值
【发布时间】:2012-06-28 12:57:49
【问题描述】:

Form 没有为我使用 spring 的 sql.date 控制器提供价值,以下是我的表单代码

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

我的控制器就是这样。

 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());

在打印时它给出 null

【问题讨论】:

  • @ModelAttribute 注释在哪里?

标签: java forms spring jakarta-ee spring-mvc


【解决方案1】:

我猜你需要去掉“ReadOnly=true”,如果readOnly设置为true,这个值就不会随请求一起传递。

【讨论】:

    【解决方案2】:

    你需要有

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

    用“util.date”代替“sql.date”

    也可以尝试删除属性“只读”

    【讨论】:

    • 为什么我要求删除只读属性,至于属性 disabled="true",值不会随请求一起发送。所以只是想检查天气值是否传递到服务器。
    猜你喜欢
    • 2018-09-16
    • 2012-10-23
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2014-04-26
    • 1970-01-01
    • 2021-04-18
    • 2014-05-21
    相关资源
    最近更新 更多