scala - Play 2.5 中 jodaDate 映射的可接受格式

标签 scala jodatime playframework-2.5

我正在尝试使用 PlayFramework 日期映射和 datetime-local 字段。 Docs Here

截断的映射看起来像这样,我为验证器尝试了几个选项。

mapping(
  "startTimeGt" -> optional(jodaDate),
  "startTimeLt" -> optional(jodaDate("dd-MM-yyyy HH:mm"))
)(...

我已经尝试了捆绑的 inputDate 助手和 datetime-local 字段。

但无论我尝试什么组合,我都会得到 error.date在表单提交上。我觉得这应该很简单,或者我在文档中遗漏了一些东西,或者他们只是不告诉我。有没有人得到所需 html 的工作示例和 jodaDate映射?

最佳答案

我猜 formWithErrors 是由代码引起的

"startTimeLt" -> optional(jodaDate("dd-MM-yyyy HH:mm"))// the format maybe wrong

因为你不知道 jodaDate 从前端传递到后端的格式。您可以在从请求中绑定(bind)表单之前打印表单内容,如下所示
def index() { implicit request =>
    println(request)//it will print the request content and you can find the "startTimeLt" to verify its format
    form.bindFromRequest.fold...
}

祝你好运

关于scala - Play 2.5 中 jodaDate 映射的可接受格式,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37613218/

相关文章:

scala - "missing boundary headers"与 scala play 中的 ws.url

playframework - 使用 logback.groovy 配置 Play Framework 日志记录

scala - 如何发现未追踪的 future ?

java - 为什么 List<Object[]> 需要显式转换才能转换为 Scala 集合?

java - jodatime DateTime 对象和 Locale

没有 ":"的时区的 java 日期模式

scala - 使用 Guice 注入(inject) Akka Actor 来玩 Framework 2.5 失败

scala - 拆分 sbt 多模块项目 scala 构建文件

scala - 如何简化 bool 元素的 foldLeft 操作?

java - 包含日期范围检查在 Joda 时间