I can't use the + operator with resultado[0] + obj.nopersonas, nopersonas is an Integer.
fhinicio(blank:false, validator : { val, obj ->
def diff = groovy.time.TimeCategory.minus(obj.fhfinal, val)
def total = diff.hours*60 + diff.minutes
if (total < 15){
return "reserva.fhfinal.tiempo.min.label"
} else {
if (total > 60) {
return "reserva.fhfinal.tiempo.max.label"
} else {
def reserva = Reserva.createCriteria()
def resultado = reserva.list() {
or {
and {
ge('fhinicio', val)
le('fhinicio', obj.fhfinal)
}
and {
ge('fhfinal', val)
le('fhfinal', obj.fhfinal)
}
}
projections {
sum('nopersonas')
}
}
//this is not working
def aff = resultado[0] + obj.nopersonas
Cannot execute null+null. Stacktrace follows: Message: Cannot execute null+null
You've got a couple of problems to resolve:
obj.nopersonasis nullThe criteria query
To fix the criteria query, start without the projection:
Make sure you're getting the appropriate instances of
Reserva. Then, add the projection and since you're expecting a single value, use the get() method instead of list().obj.nopersonas
Since
obj.nopersonasis null, I'm assuming the property is nullable. If the property is supposed to be nullable, then you'll need to account for that in your validator.