/ Published in: Java

The data source which can be used in combination with jasper reports.
Expand |
Embed | Plain Text
Copy this code and paste it in your HTML
import net.sf.jasperreports.engine.JRDataSource; import net.sf.jasperreports.engine.JRException; import net.sf.jasperreports.engine.JRField; import java.util.*; public class HibernateQueryResultDataSource implements JRDataSource { /** this is only for clarity */ this.iterator = list.iterator(); this.name=name; } return currentValue.get(field.getName()); } public boolean next() throws JRException { currentValue = iterator.hasNext() ? iterator.next() : null; return (currentValue != null); } return iterator; } } // A usage example private JRPdfExporter jRPdfExporter; try { jRPdfExporter.setParameter(JRPdfExporterParameter.CHARACTER_ENCODING, "UTF-8"); jRPdfExporter.setParameter(JRPdfExporterParameter.FONT_MAP, fontMap); final JasperPrint jasperPrint = JasperFillManager.fillReport(GeneratedPath + compiler.getRelevantEntryReportName(), new HashMap(0), ds); jRPdfExporter.setParameter(JRPdfExporterParameter.JASPER_PRINT, jasperPrint); jRPdfExporter.setParameter(JRPdfExporterParameter.OUTPUT_FILE_NAME, System.getProperty("java.io.tmpdir") + "/" + pdfFileName); jRPdfExporter.exportReport(); return true; log.error(e); return false; } }
Comments
