I’m trying to get a Criteria query to be exported to CSV, Excel, what have you. The issue I’m running into is that the categories code runs cleanly (as in, doesn’t throw any errors), but it doesn’t generate any data. I know for a fact that data is an ArrayList of List. Anyone have a workaround for this, or tell me if I’m doing something wrong?
Here’s my domain object:
class Machine {
String name,
category
// constraints, etc
}
Here’s my controller action (taken mostly from the plugin page):
def categories = {
if(params?.format && params.format != "html"){
response.contentType = ConfigurationHolder.config.grails.mime.types[params.format]
response.setHeader("Content-disposition", "attachment; filename=categories.${params.extension}")
def data = Machine.createCriteria().list {
projections {
groupProperty("category")
countDistinct("id")
}
}
exportService.export(params.format, response.outputStream, data, [:], [:])
}
Here’s one possible solution that I thought of as soon as I submitted the question: Expando. Here’s the changes to the controller method:
I’m exploiting the fact that the Export plugin tries to get a value from an object. So, I give it an object.
If there’s a better solution, I’ll be more than happy to see it.