I am some what new to Grails but I have been working on this issue for over a week and I have gotten no where: I am trying to store one array of integers and two arrays of BigDecimals into the property of my domain. The domain will be populated once then the data will only be returned in the form of a JSON.
Here is my code:
domain:
controller:class HeatMap {
BigDecimal measure
def idKey
def latPath
def lngPath
HeatMap() {}
HeatMap(idKey, latPath, lngPath) {
this.idKey = idKey
this.latPath = latPath
this.lngPath = lngPath
}
public calculateMeasure(results) {
def value = 0
results.each { current ->
value += current
}
this.measure = value
}
static constraints = {
measure(nullable: true)
idKey(blank: false)
latPath(blank: false)
lngPath(blank: false)
}
}
service:def getHeatMap = {
if(!HeatMap.count()) {
heatMapService.main(Company.list(), 48280.32)
HeatMap.list().each { h ->
//println "idKey - "+h.idKey
def value = Company.getAll(h.idKey).collect {
//println "OPAT - "+it.OPAT
if(it.OPAT == null) {
return 0
}
else {
return it.OPAT
}
}
h.calculateMeasure(value)
//println "measure - "+h.measure
}
}
def maxMeasure = 0
//println HeatMap.getAt(1).idKey
def paths = HeatMap.list().collect { h ->
if(h.measure > maxMeasure) {
maxMeasure = h.measure
}
//println h.idKey
return [
id: h.id,
idKey: h.idKey,
measure: h.measure,
latPath: h.latPath,
lngPath: h.lngPath,
]
}
def results = ["maxMeasure":maxMeasure, "paths"aths]
render results as JSON
}
What Happens:public createRegion(ID, center) {
def latPath = []
def lngPath = []
for(def i=0; i<numOfSides; i++) {
def point = center.travelFor((radius / ID.size()), ((360/numOfSides) * (i+1)))
latPath.push(point.lat)
lngPath.push(point.lng)
}
def trueID = ID.collect { objectList[it as int].id }
new HeatMap(trueID, latPath, lngPath).save(flush:true, failOnError: true)
}
the first time my controller is called and the domain is populated I get the correct information back, which is this:
The Problem:{"maxMeasure":1318439,"paths":[{"id":1,"idKey":[1],"measure":149649,"latPath":[41.50808513097997, 41.507...],"lngPath":[-74.03234239041699, -74.02...]},{"id":2,...},{...},...]}
my problem is when I refresh the page(or any time the controller is called from then on) I get back null values:
I don't understand why this is happen when I refresh the page. Can anyone Help?{"maxMeasure":1318439,"paths":[{"id":1, "idKey":null, "measure":149649, "latPath":null, "lngPath":null},{"id":2, "idKey":null, "measure":174382, "latPath":null, "lngPath":null}, ...]}


aths]
Reply With Quote
ouble, lngPath
