Simplest way to retrieve a date (submitted from datePicker) in a controller

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
3 messages Options
Reply | Threaded
Open this post in threaded view
|

Simplest way to retrieve a date (submitted from datePicker) in a controller

Marcel Overdijk
I'm looking to find the simplest and cleanest way to retrieve a date submitted from a datepicker in a controller.

- params.date(..) won't help as I need to specify a format; so no out-of-the-box integration between datePicker and params.date(..)

Then I thought to use something like this:

def day(Date date) {

}

But when submitting the the date via the datePicker I get:

No signature of method: java.util.GregorianCalendar.setTime() is applicable for argument types: (java.lang.String) values: [Sun Oct 07 00:00:00 CEST 2012] Possible solutions: setTime(java.util.Date), getTime(), clearTime(), setTimeZone(java.util.TimeZone), setTimeZone(java.util.TimeZone), set(java.util.Map)

So also here there seems no integration with the struct submitted by the datePicker.


Probably best way is to use simple Command Object containing a date.
But imo it's a little bit overkill to use a Command Object for just 1 simple property...
Just like for show(Long id) also no Command Object is used.

Am I missing some option here perhaps?


Reply | Threaded
Open this post in threaded view
|

Re: Simplest way to retrieve a date (submitted from datePicker) in a controller

Marcel Overdijk
How funny, just bumped GRAILS-3740 I created myself in 2008 :-O

Which is basically ended up in Grails 1.2 as Better Date parsing

If you submit a date from a <g:datePicker name="foo" /> tag, obtaining the Date object is now as simple as looking it up from the params object by name (eg. params.foo )


Now I tried this but it does not seem to work (anymore).

Given this datePicker in a view

<g:datePicker name="date" precision="day" />

Returns the following:

def d = params.date
println "d = ${d.class}" >> class java.lang.String


Has something changed since then?
I'm using latest 2.1.1 at the moment



Reply | Threaded
Open this post in threaded view
|

Re: Simplest way to retrieve a date (submitted from datePicker) in a controller

Jeff Brown-4
In reply to this post by Marcel Overdijk

On Oct 8, 2012, at 3:39 AM, Marcel Overdijk wrote:

> I'm looking to find the simplest and cleanest way to retrieve a date
> submitted from a datepicker in a controller.
>
> - *params.date(..)* won't help as I need to specify a format; so no
> out-of-the-box integration between datePicker and params.date(..)
>

Does this work?...

// pass the format as the 2nd argument...
def d = params.date('parameterName', 'YYYY-mm-DD ss')



JSB

--
Jeff Brown
SpringSource
http://www.springsource.com/

Autism Strikes 1 in 166
Find The Cause ~ Find The Cure
http://www.autismspeaks.org/


---------------------------------------------------------------------
To unsubscribe from this list, please visit:

    http://xircles.codehaus.org/manage_email