I'm following a tutorial which explains how to generate reports with iReport
using JSF
. I mounted my report in iReport and it is working perfectly, that is when I give a preview all the data the bank I selected is loaded into the report. The problem starts when I try to generate this report:
This is the first error:
java.lang.NullPointerException at java.lang.Class.isAssignableFrom (Native Method) at net.sf.jasperreports.engine.fill.JRFillTextField.getFormat (JRFillTextField.java:706)
Then this:
SEVERE: System error: null javax.faces.FacesException at com.sun.faces.lifecycle.InvokeApplicationPhase.execute (InvokeApplicationPhase.java:89)
And this:
Caused by: java.lang.NullPointerException at org.primefaces.component.filedownload.FileDownloadActionListener.processAction (FileDownloadActionListener.java:81)
Method that generates report:
public StreamedContent getSampleReportPDF(){
InputStream relatorio = null;
try {
String pdfFile = "C:\sampleReport.pdf";
ByteArrayOutputStream Teste = new ByteArrayOutputStream();
JasperReport jasperReport = (JasperReport)JRLoader.loadObject(getClass().getClassLoader().getResourceAsStream("Report/RelatorioReembolso.jasper"));
jasperReport.setWhenNoDataType(WhenNoDataTypeEnum.ALL_SECTIONS_NO_DETAIL);
HashMap<String, String> params = new HashMap<String, String>();
JasperPrint print = JasperFillManager.fillReport(jasperReport, params, ConexaoMysql.abrir());
JRExporter exporter = new net.sf.jasperreports.engine.export.JRPdfExporter();
exporter.setParameter(JRExporterParameter.OUTPUT_FILE_NAME, pdfFile);
exporter.setParameter(JRExporterParameter.OUTPUT_STREAM, Teste);
exporter.setParameter(JRExporterParameter.JASPER_PRINT, print);
exporter.exportReport();
relatorio = new ByteArrayInputStream(Teste.toByteArray());
} catch (JRException ex) {
ex.printStackTrace();
} catch (Exception e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
return new DefaultStreamedContent(relatorio);
}
Button that downloads generated report:
<p:commandButton rendered="true" id="exportar" title="Exportar" ajax="false">
<p:fileDownload value="#{listarReembolsoBean.sampleReportPDF}" />
</p:commandButton>