0
I’m following a tutorial which explains how to generate reports with iReport
using JSF
. I set up my report on iReport and it is working perfectly, I mean when I give a preview all data from the database I selected is loaded into the report. The problem starts when I try to generate that report:
That’s the first mistake:
java.lang.Nullpointerexception at java.lang.Class.isAssignableFrom(Native Method) at net.sf.jasperreports.engine.Fill.JRFillTextField.getFormat(Jrfilltextfield.java:706)
Then that:
GRAVE: 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 generating the 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 the generated report:
<p:commandButton rendered="true" id="exportar" title="Exportar" ajax="false">
<p:fileDownload value="#{listarReembolsoBean.sampleReportPDF}" />
</p:commandButton>