One of my co-workers has written an application in Grails 2.4.4 (I know, it's dated). One problem the app has is that you can enter a date like 2/31/2015 and it will be accepted as valid and will show up in your domain object as 3/3/2015 instead.
Is there any easy way to prevent this from happening using grails? Or do we instead have to rely on client side validation for this particular property?
Thanks.
Assuming that Grails is using DateFormat to parse the date
String, the issue is that it's using a lenientCalendar. For example, with lenient set to true (the default), the result is as you described:But, if you change it to false, you'll get an exception for the same date:
So to handle this validation in your controller, you can
Stringrather than aDate, and perform the date validation.