DZone Snippets is a public source code repository. Easily build up your personal collection of code snippets, categorize them with tags / keywords, and share them with the world
Print JasperReport Without A DataSource
This is a method that fills a Jasper Reports .jasper file using only parameters. No Data Source is needed. Note: "module" is an object whose fields are used as the parameters to the report. The method also calls JasperViewer.viewReport which starts the embedded Jasper Reports viewer. This could be replaced with a method to export the report or anything else.
private void printCertsActionPerformed(java.awt.event.ActionEvent evt) {
File reportFile = new File("report1.jasper");
Map parameters = new HashMap();
parameters.put("partNum", module.getPartNum());
parameters.put("moduleType", module.getModuleType());
parameters.put("area", module.getArea());
parameters.put("membraneType", module.getMembraneMaterial());
parameters.put("channelHeight", module.getChannelHeight());
parameters.put("controlNum", cnField.getText());
try {
JasperPrint print = JasperFillManager.fillReport(reportFile.getPath(), parameters, new JREmptyDataSource());
JasperViewer.viewReport(print);
} catch (JRException ex) {
Logger.getLogger(TestDashboardView.class.getName()).log(Level.SEVERE, null, ex);
}
}




