Problem getting export plugin to work

classic Classic list List threaded Threaded
7 messages Options
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Problem getting export plugin to work

martinjconnolly
Hi all, I just tried to use the export pluging in my Grails 1.3.8 app. I have followed all the instructions, and copied the example code into my controller, changing the class name of course. If I use the markup
<r:require module="export"/>
 in my GSP I get the error:
 Module [export] depends on resource [/css/export.css] but the file cannot be found 
 when I load my list page. So if I change it to the old version
<export:resource />
 the page loads, but then when I choose one of the export options I get this error thrown:

ERROR errors.GrailsExceptionResolver  - Exception occurred when processing request: [GET] /BlueAccounts/account/list - parameters:
format: excel
extension: xls
Stacktrace follows:
java.lang.NullPointerException: Cannot invoke method export() on null object
	at oss.AccountController$_closure2.doCall(AccountController.groovy:21)
	at oss.AccountController$_closure2.doCall(AccountController.groovy)
	at org.grails.plugin.resource.DevModeSanityFilter.doFilter(DevModeSanityFilter.groovy:44)
	at java.lang.Thread.run(Thread.java:736)

This is the list method in my controller:

def list = {
		def exportService

        params.max = Math.min(params.max ? params.int('max') : 10, 100)
		if(params?.format && params.format != "html")
		{ response.contentType = ConfigurationHolder.config.grails.mime.types[params.format] 
			response.setHeader("Content-disposition", "attachment; filename=blueaccounts.${params.extension}")
			
			exportService.export(params.format, response.outputStream,Account.list(params), [:], [:]) 
		}
		[accountInstanceList: Account.list(params), accountInstanceTotal: Account.count()]
    }
Can anyone suggest how to resolve this please? Thanks
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: Problem getting export plugin to work

andreas.schmitt
Hi Martin,

thank you for choosing export plugin. I think the problem is the place
where you put "def exportService". The service will not get injected
when defined there. Please try to define it outside of the closure e.g.:

def exportService

def list =3D {
        params.max =3D Math.min(params.max ? params.int('max') : 10, 100)
       ...
 }

This should resolve it.

Best regards,
Andreas
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: Problem getting export plugin to work

martinjconnolly
Thanks, that solved the immediate problem and I can now export a file. But now I find that it exports only the first n rows (n determined by the max parameter), regardless of which page I am on. Again, sorry if I am missing something..
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: Problem getting export plugin to work

andreas.schmitt
Hi Martin,

yes, that's right. The export plugin exports all the data you pass to it.
Using Account.list(params) limits the results by the max value, because of params.max.

If you would like to export all records you can pass the whole list of domain objects by
using Account.list() without params e.g.

exportService.export(params.format, response.outputStream,Account.list(), [:], [:])

Best regards,
Andreas
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: Problem getting export plugin to work

martinjconnolly
Andreas, how can I pass a variable into the link to generate an Excel file? For example I can add a "?country=Germany" parameter to my list action and it only returns values for Germany. But the link from the Excel button does not include that parameter so it exports all the data for all countries -  how do I get it to include it?
Thanks
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: Problem getting export plugin to work

martinjconnolly
ignore the question, I found the way to do this in the docs
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: Problem getting export plugin to work

mfipa
can you share the document so that i can do it also.please.
Loading...