I have an error when exporting a report to pdf
I am using Jasper Report 5.6.0
before the report I exported it well but now I do not want to do it and in the log I do not have any error this is the code to print
public void PDF() throws JRException, IOException {
EntityManagerFactory emf = Persistence.createEntityManagerFactory("plantaPU");
EntityManager em = emf.createEntityManager();
em.getEntityManagerFactory().getCache().evictAll();
Query query = em.createQuery("select s from ticket s where s.id='" + ticketID + "'");
List<ticket> listTicket = (List<ticket>) query.getResultList();
JRBeanCollectionDataSource beanCollectionDataSource = new JRBeanCollectionDataSource(listTicket);
String reportPath = FacesContext.getCurrentInstance().getExternalContext().getRealPath("/reports/report1.jasper");
JasperPrint jasperPrint = JasperFillManager.fillReport(reportPath, new HashMap(), beanCollectionDataSource);
HttpServletResponse httpServletResponse = (HttpServletResponse) FacesContext.getCurrentInstance().getExternalContext().getResponse();
httpServletResponse.addHeader("Content-disposition", "attachment; filename=report.pdf");
ServletOutputStream servletOutputStream;
servletOutputStream = httpServletResponse.getOutputStream();
JasperExportManager.exportReportToPdfStream(jasperPrint, servletOutputStream);
FacesContext.getCurrentInstance().responseComplete();
}
and that's what I call from the page
<p:commandButton value="Imprimir" action="#{verTicketController.PDF()}"/>