Constraints limitation on Numeric values and dates

classic Classic list List threaded Threaded
2 messages Options
Reply | Threaded
Open this post in threaded view
|

Constraints limitation on Numeric values and dates

OlivierD
Hello,

1. We would like to validate an Integer field, alerting the user if he tries to add a non numeric char,
but the field is automatically set to null if it is not numeric. We would like to show an error message
and redisplay what the user has entered.
It has already been discussed, but we can not find a workaround. What can we do, other than
using a String and validate with a custom validator ?

2. We would like to validate the date, like the java Calendar class with setLenient(false). If the user
tries to set the date to for eg. 30 february, we would like to show an error message and not set
automatically the date to 1st or 2 march. When the validator is runned, the date fields (day,month,year)
are already interpreted and tranformed to a Date Object so we can not check the original fields.
What can we do ?

Thanks,

Olivier
Reply | Threaded
Open this post in threaded view
|

Re: Constraints limitation on Numeric values and dates

graemer
On 10/9/07, OlivierD <[hidden email]> wrote:

>
> Hello,
>
> 1. We would like to validate an Integer field, alerting the user if he tries
> to add a non numeric char,
> but the field is automatically set to null if it is not numeric. We would
> like to show an error message
> and redisplay what the user has entered.
> It has already been discussed, but we can not find a workaround. What can we
> do, other than
> using a String and validate with a custom validator ?

In the next version of Grails (1.0-RC1) we store the original values
and type conversion errors during binding so if you do

def b = new Book(params)

you can check for errors:

if(b.hasErrors()) {}

And obtain the original input value:

b.errors.getFieldError("price")

>
> 2. We would like to validate the date, like the java Calendar class with
> setLenient(false). If the user
> tries to set the date to for eg. 30 february, we would like to show an error
> message and not set
> automatically the date to 1st or 2 march. When the validator is runned, the
> date fields (day,month,year)
> are already interpreted and tranformed to a Date Object so we can not check
> the original fields.
> What can we do ?


>
> Thanks,
>
> Olivier
> --
> View this message in context: http://www.nabble.com/Constraints-limitation-on-Numeric-values-and-dates-tf4594688.html#a13117141
> Sent from the grails - user mailing list archive at Nabble.com.
>
>
> ---------------------------------------------------------------------
> To unsubscribe from this list please visit:
>
>     http://xircles.codehaus.org/manage_email
>
>


--
Graeme Rocher
Grails Project Lead
http://grails.org

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

    http://xircles.codehaus.org/manage_email