I have an input field where I enter a value, the millis
parameter, that is used as parameter to generate a Jasperreport. I´m using Ajax to call the controller that generates the report. The problem is that, although the report seems to be successfully generated, the download dialog is never shown.
Here´s part of my code:
/*THE BUTTON USED FOR MY GSP VIEW*/
<button id="imprimir" type="button">IMPRIMIR LOTES LIQUIDADOS</button>
/*JAVASCRIPT CODE TO CALL THE CONTROLLER*/
$("#imprimir").bind("click",imprimir);
function imprimir(){
$.ajax({
url: "/Liquidaciones/liquidacionDeComplejo/crearReporteGrupal2",
dataType: 'json',
data: {
millis:$("#millis").val()
},
success: function(data) {
},
error: function(request, status, error) {
}
});
}
/*GRAILS CONTROLLER THAT GENERATES DE REPORT*/
def crearReporteGrupal2 = {
Map reportParams = [:]
def millis = params.millis.toBigDecimal()
def realPath = servletContext.getRealPath("/reports/images/")
reportParams.put("millis",millis)
reportParams.put("realPath",realPath+"/")
reportParams.put("SUBREPORT_DIR","${servletContext.getRealPath('/reports')}/")
def reportDef = new JasperReportDef(name:'liquidacion_grupal_complejo.jasper',fileFormat:JasperExportFormat.PDF_FORMAT,parameters: reportParams)
byte[] bytes
bytes = jasperService.generateReport(reportDef).toByteArray()
response.addHeader("Content-Disposition", 'attachment; filename="liquidacion_grupal.pdf"')
response.contentType = 'application/pdf'
response.outputStream << bytes
response.outputStream.flush()
//I read somewhere that is necessary to return 'something' to initiate the download
//but it didn't help
//return null
//render [:] as JSON
}
Here the result from the server:
But when I copy this URL:/Liquidaciones/liquidacionDeComplejo/crearReporteGrupal2?millis=1420757752558
from the Web Console and paste it in a new tab the download dialog appears.
Please help me!
Thanks in advance.