I making report engine with JasperReport. Everything works fine so far but I have small miss understanding. In my code I'm trying to compile template file and return JasperReport object and if the compilation is failed then compile another file and return error message. But it does not work for some reason. Here is my code:
/**
* Generates JasperPrint object from the Template file
* @param Template File Name (String)
* @param Parameters (Map<String, Object>)
* @param Collection of Value Objects (Collection, List, ArrayList)
* @return JasperPrint
*/
private JasperPrint getJRPrint(String tmpltFileLocation, Map<String, Object> params, JRBeanCollectionDataSource dataSource) {
JasperPrint jrPrint = null;
log.info("ReportEngine: compiling " + tmpltFileLocation);
try {
JasperReport jasperReport = JasperCompileManager.compileReport(tmpltFileLocation);
jrPrint = JasperFillManager.fillReport(jasperReport, params, dataSource);
} catch (JRException ex) {
ex.printStackTrace();
return getErrorJRPrint(ex);
}
return jrPrint;
}
private JasperPrint getErrorJRPrint(Exception ex) {
JasperPrint errJrPrint = null;
Map<String, Object> errParams = new HashMap<String, Object>();
errParams.put("errorMessage", ex.getMessage());
try {
JasperReport jasperReport = JasperCompileManager.compileReport(reportFolderName + "errReport.jrxml");
errJrPrint = JasperFillManager.fillReport(jasperReport, errParams);
} catch (Exception ex2) {
ex2.printStackTrace();
}
return errJrPrint;
}
The error Template file is there (I tried to delete it and it complains that the file is missing, so it can see it). In my template file I'm just printing error message and also I tried to print some static text but it does not work. What could be the problem?