I want to use grails export plugin to get my Domain classes exportables into xls and csv files.
In my main layout named front.gsp, I did that :
<!DOCTYPE html>
<html lang="en">
<head>
...
<g:layoutHead />
</head>
<body>
<sec:ifLoggedIn>
<r:require module="export"/>
<export:formats formats="['csv', 'excel', 'ods', 'pdf', 'rtf', 'xml']" action="exportTest" />
...
<g:layoutBody />
<r:layoutResources/>
<script type="text/javascript" src="${resource(dir: 'js', file: 'jquery.min.js')}"></script>
<script type="text/javascript" src="${resource(dir: 'js', file: 'bootstrap.min.js')}"></script>
<script type="text/javascript" src="${resource(dir: 'js', file: 'application.js')}"></script>
</body>
</html>
Into my DomainClassController.groovy I did that :
def exportTest() {
if(!params.max) params.max = 10
if(params?.format && params.format != "html"){
response.contentType = grailsApplication.config.grails.mime.types[params.format] response.setHeader("Content-disposition", "attachment; filename=contacts.${params.extension}")
exportService.export(
params.format,
response.outputStream,
ContactDTO.list(params),
[:],
[:])
[contactDTOInstanceList: ContactDTO.list( params )]
}
}
I also create a view named exportTest.gsp into my view folder of my controller, just empty file to temporarely solve 404 issue.
I did not have any error messages but when I'm clicking on any export button, I'm redirecting to my page exportTest.gsp and no file is downloaded
How can I get a downloaded file using grails export plugin ? I follow the user guide, don't have any errors (solved) but no file is created ?
Thanks for reading !
Snite
EDIT : I just see that, when clicking on export link, the generated url is :
http://localhost:8080/site/controller/action?format=excel&extension=xls
But strangely, when making a "println params" into my controller, output is :
[extension:xls, action:exportTest, format:null, controller:contactDTO, max:10]
params.format is null BUT set into url ?!!!
Change url like that (and adapting controller code) :
http://localhost:8080/site/controller/action?formatD=excel&extension=xls
Give me the following error :
Firefox ne peut trouver le fichier à l'adresse http://localhost:8080/site/controller/action?formatd=excel&extension=xls.