I am using Grails version 2.3.3, and groovy version 2.1.8.
I am using an online tutorial to help learn Grails web dev, and I have created a domain class with the following constraints
package racetrack
class Race {
static constraints = {
name(blank:false, maxSize:50)
city(blank:false)
state(inList:["GA", "NC", "SC", "VA"])
startDate()
distance(min: 0.0)
cost(min: new BigDecimal(0.0), max: new BigDecimal(100.0))
maxRunners(min:0, max:100000)
}
String name
Date startDate
String city
String state
BigDecimal distance
BigDecimal cost
Integer maxRunners
}
I'm using scaffolding so I have full CRUD functionality. The problem is, when I go to create a new Race, the app allows me to input values like "-1" in both the distance and cost fields, and values like "200" for the cost field. I noticed that the Integer field maxRunners was working correctly, as it displays a warning message if I try to put in -1 maxRunners. I changed the cost field to be of type Integer, and then the constraints started working.
Why is this happening? I copy and pasted the code from the tutorial into my text file and the constraints to not work for BigDecimal type fields.