Created
November 19, 2016 15:13
-
-
Save SergioDiniz/ab36d4cb015f61d0d66e08a9651e47f3 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
private JasperPrint jasperPrint; | |
public void init() throws JRException{ | |
JRBeanCollectionDataSource data = new JRBeanCollectionDataSource(listOfUser); | |
String reportPath = FacesContext.getCurrentInstance().getExternalContext().getRealPath(“report.jasper”); | |
jasperPrint = JasperFillManager.fillReport(reportPath, new HashMap<>(), data); | |
} | |
public void PDF() throws JRException, IOException{ | |
init(); | |
HttpServletResponse response = (HttpServletResponse) FacesContext.getCurrentInstance().getExternalContext().getResponse(); | |
response.reset(); | |
response.setContentType("application/pdf"); | |
response.setHeader("Content-disposition", "attachment; filename=\"report.pdf\""); | |
ServletOutputStream stream = response.getOutputStream(); | |
JasperExportManager.exportReportToPdfStream(jasperPrint, stream); | |
FacesContext.getCurrentInstance().responseComplete(); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment