【问题标题】:Dojo/Spring DateTextBox initialization fails with Date value, works with String?Dojo/Spring DateTextBox 初始化失败,日期值,使用字符串?
【发布时间】:2013-02-15 05:27:09
【问题描述】:

我正在努力从 Web 表单到 Spring 控制器来回获取 Date 值。将此值作为字符串传递时一切正常,但由于它在逻辑上是“日期”值,因此我将其更改为日期,一切都变得很糟糕。

我尝试了here 指示的修复,但没有奏效。

这是我在运行时遇到的错误(来自“locale.js”):

Uncaught TypeError: Object 2/28/13 has no method 'getMonth' 

页面是使用带有 Spring Forms 标记(form:form、form:input 等)的 JSP 构建的,并且客户端验证是使用依赖于 Dojo Javascript 库的 SpringValidation 装饰器完成的。

这是我要传递的字段:

@NotEmpty
@DateTimeFormat(style="S-")
private Date startDate;

这是 Javascript/Dojo 客户端验证代码:

Spring.addDecoration(new Spring.ElementDecoration({
    elementId : "startDate",
    widgetType : "dijit.form.DateTextBox",
    widgetAttrs : {
        missingMessage : parms.required,
        invalidMessage : parms.wrongFormatMessage,
        required : true,
        regExp : parms.textFieldPattern }
}));

这是实际的表单标签:

<form:input id="startDate" path="startDate" />

有人有什么想法吗?它发生在 Dojo/Spring 内部的某个地方,我不确定为什么如果我传递一个“日期”它会失败,但如果我传递一个包含日期值的“字符串”它会工作。

【问题讨论】:

    标签: java javascript spring dojo


    【解决方案1】:

    问题出在表单支持对象上的 Date 属性的 @DateTimeFormat 上。这不起作用:

    @DateTimeFormat(style="S-")
    private Date startDate;
    

    但是这样做了:

    @DateTimeFormat(iso = DateTimeFormat.ISO.DATE)
    private Date startDate;
    

    显然 Javascript 和 Dojo DateTextBox 对日期格式非常挑剔。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2018-06-10
      • 2020-06-29
      • 2013-10-20
      • 2017-03-17
      • 2014-09-13
      • 1970-01-01
      相关资源
      最近更新 更多