I want to use the Grails export plugin to export my classes to xls and csv classes.
In my main layout called front.gsp, I did this:
<!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>
In my DomainClassController.groovy, I did this:
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 called exportTest.gsp in my view folder of my controller, just an empty file to temporarily fix 404 problem.
I had no error messages, but when I click the export button, I am redirected to the exportTest.gsp page and the file does not load
How to get downloaded file using Grails graphics adapter? I follow the user manual, there are no errors (allowed), but the file is not created?
Thank you for reading!
Snite
EDIT: I just see that when the export link is clicked, the generated URL is:
http://localhost:8080/site/controller/action?format=excel&extension=xls
But strangely enough, when creating the "println parameters" in my controller, the output is:
[extension:xls, action:exportTest, format:null, controller:contactDTO, max:10]
params.format has a null BUT value set to a URL? !!!
Change the url (and adapt the 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: