I would like to use withFormat within my scaffolding controller and added a scaffolding view 'list.csv.gsp'. But without generating my list.csv.gsp view, grails doesn't use the scaffolding list.csv.gsp view.
After generating de list.csv.gsp view it works fine. But I won't create all these views, because they are all the same.
My scaffolding controller list action ends with the code below:
withFormat {
html {
[${propertyName}List: ${propertyName}List, ${propertyName}Total: ${propertyName}List.getTotalCount(), params: cleanParams(params)]
}
csv {
response.setContentType('text/csv')
response.setHeader('Content-Disposition', "attachment; filename=\${message(code: '${domainClass.propertyName}.label')}.csv")
[${propertyName}List: ${propertyName}List]
}
}
I don't know if you still have a problem with this but the grails docs for with format have this quote:
Grails ignores the HTTP Accept header unless you add a grails.mime.use.accept.header = true setting to your Config.groovy file. In other words, withFormat() will be completely unaffected by the Accept header without that setting.
See withFormat in the grails docs.