在Grails中读取g:datePicker-value,而不使用“new Object(params)”-method [英] Reading the g:datePicker-value in Grails without using the "new Object(params)"-method

查看:107
本文介绍了在Grails中读取g:datePicker-value,而不使用“new Object(params)”-method的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

假设我有一个名为foobar的datePicker:

 < g:datePicker name =foobarvalue = $ {new Date()}precision =day/> 

如何阅读此日期选择器的提交值?



一种有效但有一些不必要的副作用的方法如下:

  def newObject = new SomeClassName(params)
printlnvalue =+ newObject.foobar

它将所有提交的字段读入newObject,这是我想要避免的。我只对foobar字段的价值感兴趣。



我最初假设的方式可以是:

  def newObject = new SomeClassName()
newObject.foobar = params [foobar]

但是Grails似乎没有自动将foobar字段翻译成一个Date()对象。



更新:其他信息可以在 Grails JIRA

解决方案

读取g:datePicker值在Grails 1.2中变得更容易(参见发行说明):


更好的日期解析



如果您从
标签提交日期,则
获取Date对象现在为
简单,从
params对象查找它e(例如params.foo



Let's say I have a datePicker called "foobar":

<g:datePicker name="foobar" value="${new Date()}" precision="day" />

How do I read the submitted value of this date-picker?

One way which works but has some unwanted side-effects is the following:

def newObject = new SomeClassName(params)
println "value=" + newObject.foobar

This way of doing it reads all submitted fields into newObject which is something I want to avoid. I'm only interested in the value of the "foobar" field.

The way I originally assumed this could be done was:

def newObject = new SomeClassName()
newObject.foobar = params["foobar"]

But Grails does not seem to automatically do the translation of the foobar field into a Date() object.

Updated: Additional information can be found in the Grails JIRA.

解决方案

Reading the g:datePicker value became a lot easier in Grails 1.2 (see release notes):

Better Date parsing

If you submit a date from a tag, obtaining the Date object is now as simple as looking it up from the params object by name (eg. params.foo )

这篇关于在Grails中读取g:datePicker-value,而不使用“new Object(params)”-method的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆