Java Code Examples for net.sf.jasperreports.engine.JasperFillManager#fillReport()
The following examples show how to use
net.sf.jasperreports.engine.JasperFillManager#fillReport() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: AdminJasperReport.java From Spring-MVC-Blueprints with MIT License | 7 votes |
@RequestMapping(value = "/hrms/showJasperManagerPDF", method = RequestMethod.GET) public String showJasperManagerPDF(ModelMap model, HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException, JRException, NamingException { usersList = loginService.getUserList(); AdminJasperBase dsUsers = new AdminJasperBase(usersList); Map<String, Object> params = new HashMap<>(); params.put("users", usersList); JasperReport jasperReport = getCompiledFile("JRUsers", request); JasperPrint jasperPrint = JasperFillManager.fillReport(jasperReport, params, dsUsers); response.setContentType("application/x-pdf"); response.setHeader("Content-disposition", "inline; filename=userList.pdf"); final OutputStream outStream = response.getOutputStream(); JasperExportManager.exportReportToPdfStream(jasperPrint, outStream); return null; }
Example 2
Source File: AbstractJasperReportsView.java From lams with GNU General Public License v2.0 | 7 votes |
/** * Fill the given report using the given JDBC DataSource and model. */ private JasperPrint doFillReport(JasperReport report, Map<String, Object> model, DataSource ds) throws Exception { // Use the JDBC DataSource. if (logger.isDebugEnabled()) { logger.debug("Filling report using JDBC DataSource [" + ds + "]"); } Connection con = ds.getConnection(); try { return JasperFillManager.fillReport(report, model, con); } finally { try { con.close(); } catch (Throwable ex) { logger.debug("Could not close JDBC Connection", ex); } } }
Example 3
Source File: AbstractJasperReportsView.java From spring4-understanding with Apache License 2.0 | 6 votes |
/** * Fill the given report using the given JDBC DataSource and model. */ private JasperPrint doFillReport(JasperReport report, Map<String, Object> model, DataSource ds) throws Exception { // Use the JDBC DataSource. if (logger.isDebugEnabled()) { logger.debug("Filling report using JDBC DataSource [" + ds + "]"); } Connection con = ds.getConnection(); try { return JasperFillManager.fillReport(report, model, con); } finally { try { con.close(); } catch (Throwable ex) { logger.debug("Could not close JDBC Connection", ex); } } }
Example 4
Source File: ShowReport.java From Hotel-Properties-Management-System with GNU General Public License v2.0 | 5 votes |
public void loadReport(String reportName, ReportObject reportObject) { logging = LoggingEngine.getInstance(); try { final InputStream inputStream = ShowReport.class .getResourceAsStream("/com/coder/hms/reportTemplates/" + reportName + ".jrxml"); JasperReport report = JasperCompileManager.compileReport(inputStream); HashMap<String, Object> parameters = new HashMap<String, Object>(); List<ReportObject> list = new ArrayList<ReportObject>(); list.add(reportObject); JRBeanCollectionDataSource beanColDataSource = new JRBeanCollectionDataSource(list); JasperPrint jasperPrint = JasperFillManager.fillReport(report, parameters, beanColDataSource); final JRViewer viewer = new JRViewer(jasperPrint); setType(Type.POPUP); setResizable(false); setModalExclusionType(ModalExclusionType.APPLICATION_EXCLUDE); this.setTitle("Reservation [Report]"); this.setExtendedState(Frame.MAXIMIZED_BOTH); this.setAlwaysOnTop(isAlwaysOnTopSupported()); this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); getContentPane().setLayout(new BorderLayout()); this.setIconImage(Toolkit.getDefaultToolkit(). getImage(LoginWindow.class.getResource(LOGOPATH))); this.setResizable(false); getContentPane().add(viewer, BorderLayout.CENTER); } catch (JRException e) { logging.setMessage("JRException report error!"); } }
Example 5
Source File: AlterDesignApp.java From jasperreports with GNU Lesser General Public License v3.0 | 5 votes |
/** * */ public void fill() throws JRException { long start = System.currentTimeMillis(); File sourceFile = new File("build/reports/AlterDesignReport.jasper"); System.err.println(" : " + sourceFile.getAbsolutePath()); JasperReport jasperReport = (JasperReport)JRLoader.loadObject(sourceFile); JRRectangle rectangle = (JRRectangle)jasperReport.getTitle().getElementByKey("first.rectangle"); rectangle.setForecolor(new Color((int)(16000000 * Math.random()))); rectangle.setBackcolor(new Color((int)(16000000 * Math.random()))); rectangle = (JRRectangle)jasperReport.getTitle().getElementByKey("second.rectangle"); rectangle.setForecolor(new Color((int)(16000000 * Math.random()))); rectangle.setBackcolor(new Color((int)(16000000 * Math.random()))); rectangle = (JRRectangle)jasperReport.getTitle().getElementByKey("third.rectangle"); rectangle.setForecolor(new Color((int)(16000000 * Math.random()))); rectangle.setBackcolor(new Color((int)(16000000 * Math.random()))); JRStyle style = jasperReport.getStyles()[0]; style.setFontSize(16f); style.setItalic(Boolean.TRUE); JasperPrint jasperPrint = JasperFillManager.fillReport(jasperReport, null, (JRDataSource)null); File destFile = new File(sourceFile.getParent(), jasperReport.getName() + ".jrprint"); JRSaver.saveObject(jasperPrint, destFile); System.err.println("Filling time : " + (System.currentTimeMillis() - start)); }
Example 6
Source File: SubreportApp.java From jasperreports with GNU Lesser General Public License v3.0 | 5 votes |
/** * */ public void jsonMetadata() throws JRException { long start = System.currentTimeMillis(); JasperReport subreport = (JasperReport)JRLoader.loadObjectFromFile("build/reports/ProductReport.jasper"); //Preparing parameters Map<String, Object> parameters = new HashMap<String, Object>(); parameters.put("ProductsSubreport", subreport); parameters.put(JRParameter.IS_IGNORE_PAGINATION, true); JasperPrint jasperPrint = JasperFillManager.fillReport("build/reports/MasterReport.jasper", parameters, getDemoHsqldbConnection()); System.err.println("Filling time : " + (System.currentTimeMillis() - start)); start = System.currentTimeMillis(); File destFile = new File(new File("build/reports"), jasperPrint.getName() + ".json"); JsonMetadataExporter exporter = new JsonMetadataExporter(); exporter.setExporterInput(new SimpleExporterInput(jasperPrint)); exporter.setExporterOutput(new SimpleWriterExporterOutput(destFile)); exporter.exportReport(); System.err.println("JSON creation time : " + (System.currentTimeMillis() - start)); }
Example 7
Source File: JasperReportsUtilsTests.java From spring4-understanding with Apache License 2.0 | 5 votes |
@Test public void renderWithWriter() throws Exception { StringWriter writer = new StringWriter(); JasperPrint print = JasperFillManager.fillReport(getReport(), getParameters(), getDataSource()); JasperReportsUtils.render(new JRHtmlExporter(), print, writer); String output = writer.getBuffer().toString(); assertHtmlOutputCorrect(output); }
Example 8
Source File: FillServlet.java From jasperreports with GNU Lesser General Public License v3.0 | 4 votes |
@Override public void service( HttpServletRequest request, HttpServletResponse response ) throws IOException, ServletException { ServletContext context = this.getServletConfig().getServletContext(); response.setContentType("text/html"); PrintWriter out = response.getWriter(); try { String reportFileName = context.getRealPath("/reports/WebappReport.jasper"); File reportFile = new File(reportFileName); if (!reportFile.exists()) throw new JRRuntimeException("File WebappReport.jasper not found. The report design must be compiled first."); Map<String, Object> parameters = new HashMap<String, Object>(); parameters.put("ReportTitle", "Address Report"); parameters.put("BaseDir", reportFile.getParentFile()); JasperPrint jasperPrint = JasperFillManager.fillReport( reportFileName, parameters, new WebappDataSource() ); request.getSession().setAttribute(BaseHttpServlet.DEFAULT_JASPER_PRINT_SESSION_ATTRIBUTE, jasperPrint); } catch (JRException e) { out.println("<html>"); out.println("<head>"); out.println("<title>JasperReports - Web Application Sample</title>"); out.println("<link rel=\"stylesheet\" type=\"text/css\" href=\"../stylesheet.css\" title=\"Style\">"); out.println("</head>"); out.println("<body bgcolor=\"white\">"); out.println("<span class=\"bnew\">JasperReports encountered this error :</span>"); out.println("<pre>"); e.printStackTrace(out); out.println("</pre>"); out.println("</body>"); out.println("</html>"); } out.println("<html>"); out.println("<head>"); out.println("<title>JasperReports - Web Application Sample</title>"); out.println("<link rel=\"stylesheet\" type=\"text/css\" href=\"../stylesheet.css\" title=\"Style\">"); out.println("</head>"); out.println("<body bgcolor=\"white\">"); out.println("<span class=\"bold\">The compiled report design was successfully filled with data.</span>"); out.println("</body>"); out.println("</html>"); }
Example 9
Source File: HtmlServlet.java From jasperreports with GNU Lesser General Public License v3.0 | 4 votes |
@Override public void service( HttpServletRequest request, HttpServletResponse response ) throws IOException, ServletException { ServletContext context = this.getServletConfig().getServletContext(); response.setContentType("text/html"); PrintWriter out = response.getWriter(); try { File reportFile = new File(context.getRealPath("/reports/WebappReport.jasper")); if (!reportFile.exists()) throw new JRRuntimeException("File WebappReport.jasper not found. The report design must be compiled first."); JasperReport jasperReport = (JasperReport)JRLoader.loadObjectFromFile(reportFile.getPath()); Map<String, Object> parameters = new HashMap<String, Object>(); parameters.put("ReportTitle", "Address Report"); parameters.put("BaseDir", reportFile.getParentFile()); JasperPrint jasperPrint = JasperFillManager.fillReport( jasperReport, parameters, new WebappDataSource() ); HtmlExporter exporter = new HtmlExporter(); request.getSession().setAttribute(ImageServlet.DEFAULT_JASPER_PRINT_SESSION_ATTRIBUTE, jasperPrint); exporter.setExporterInput(new SimpleExporterInput(jasperPrint)); SimpleHtmlExporterOutput output = new SimpleHtmlExporterOutput(out); output.setImageHandler(new WebHtmlResourceHandler("image?image={0}")); exporter.setExporterOutput(output); exporter.exportReport(); } catch (JRException e) { out.println("<html>"); out.println("<head>"); out.println("<title>JasperReports - Web Application Sample</title>"); out.println("<link rel=\"stylesheet\" type=\"text/css\" href=\"../stylesheet.css\" title=\"Style\">"); out.println("</head>"); out.println("<body bgcolor=\"white\">"); out.println("<span class=\"bnew\">JasperReports encountered this error :</span>"); out.println("<pre>"); e.printStackTrace(out); out.println("</pre>"); out.println("</body>"); out.println("</html>"); } }
Example 10
Source File: JasperReportsUtils.java From lams with GNU General Public License v2.0 | 3 votes |
/** * Render a report in CSV format using the supplied report data. * Writes the results to the supplied {@code Writer}. * @param report the {@code JasperReport} instance to render * @param parameters the parameters to use for rendering * @param writer the {@code Writer} to write the rendered report to * @param reportData a {@code JRDataSource}, {@code java.util.Collection} or object array * (converted accordingly), representing the report data to read fields from * @param exporterParameters a {@link Map} of {@code JRExporterParameter exporter parameters} * @throws JRException if rendering failed * @see #convertReportData */ public static void renderAsCsv(JasperReport report, Map<String, Object> parameters, Object reportData, Writer writer, Map<net.sf.jasperreports.engine.JRExporterParameter, Object> exporterParameters) throws JRException { JasperPrint print = JasperFillManager.fillReport(report, parameters, convertReportData(reportData)); JRCsvExporter exporter = new JRCsvExporter(); exporter.setParameters(exporterParameters); render(exporter, print, writer); }
Example 11
Source File: JasperReportsUtils.java From lams with GNU General Public License v2.0 | 3 votes |
/** * Render a report in HTML format using the supplied report data. * Writes the results to the supplied {@code Writer}. * @param report the {@code JasperReport} instance to render * @param parameters the parameters to use for rendering * @param writer the {@code Writer} to write the rendered report to * @param reportData a {@code JRDataSource}, {@code java.util.Collection} or object array * (converted accordingly), representing the report data to read fields from * @throws JRException if rendering failed * @see #convertReportData */ public static void renderAsHtml(JasperReport report, Map<String, Object> parameters, Object reportData, Writer writer) throws JRException { JasperPrint print = JasperFillManager.fillReport(report, parameters, convertReportData(reportData)); render(new net.sf.jasperreports.engine.export.JRHtmlExporter(), print, writer); }
Example 12
Source File: JasperReportsUtils.java From lams with GNU General Public License v2.0 | 3 votes |
/** * Render a report in HTML format using the supplied report data. * Writes the results to the supplied {@code Writer}. * @param report the {@code JasperReport} instance to render * @param parameters the parameters to use for rendering * @param writer the {@code Writer} to write the rendered report to * @param reportData a {@code JRDataSource}, {@code java.util.Collection} or object array * (converted accordingly), representing the report data to read fields from * @param exporterParameters a {@link Map} of {@code JRExporterParameter exporter parameters} * @throws JRException if rendering failed * @see #convertReportData */ public static void renderAsHtml(JasperReport report, Map<String, Object> parameters, Object reportData, Writer writer, Map<net.sf.jasperreports.engine.JRExporterParameter, Object> exporterParameters) throws JRException { JasperPrint print = JasperFillManager.fillReport(report, parameters, convertReportData(reportData)); net.sf.jasperreports.engine.export.JRHtmlExporter exporter = new net.sf.jasperreports.engine.export.JRHtmlExporter(); exporter.setParameters(exporterParameters); render(exporter, print, writer); }
Example 13
Source File: JasperReportsUtils.java From lams with GNU General Public License v2.0 | 3 votes |
/** * Render a report in PDF format using the supplied report data. * Writes the results to the supplied {@code OutputStream}. * @param report the {@code JasperReport} instance to render * @param parameters the parameters to use for rendering * @param stream the {@code OutputStream} to write the rendered report to * @param reportData a {@code JRDataSource}, {@code java.util.Collection} or object array * (converted accordingly), representing the report data to read fields from * @throws JRException if rendering failed * @see #convertReportData */ public static void renderAsPdf(JasperReport report, Map<String, Object> parameters, Object reportData, OutputStream stream) throws JRException { JasperPrint print = JasperFillManager.fillReport(report, parameters, convertReportData(reportData)); render(new JRPdfExporter(), print, stream); }
Example 14
Source File: JasperReportsUtils.java From lams with GNU General Public License v2.0 | 3 votes |
/** * Render a report in CSV format using the supplied report data. * Writes the results to the supplied {@code Writer}. * @param report the {@code JasperReport} instance to render * @param parameters the parameters to use for rendering * @param writer the {@code Writer} to write the rendered report to * @param reportData a {@code JRDataSource}, {@code java.util.Collection} or object array * (converted accordingly), representing the report data to read fields from * @throws JRException if rendering failed * @see #convertReportData */ public static void renderAsCsv(JasperReport report, Map<String, Object> parameters, Object reportData, Writer writer) throws JRException { JasperPrint print = JasperFillManager.fillReport(report, parameters, convertReportData(reportData)); render(new JRCsvExporter(), print, writer); }
Example 15
Source File: JasperReportsUtils.java From spring4-understanding with Apache License 2.0 | 3 votes |
/** * Render a report in XLS format using the supplied report data. * Writes the results to the supplied {@code OutputStream}. * @param report the {@code JasperReport} instance to render * @param parameters the parameters to use for rendering * @param stream the {@code OutputStream} to write the rendered report to * @param reportData a {@code JRDataSource}, {@code java.util.Collection} or object array * (converted accordingly), representing the report data to read fields from * @throws JRException if rendering failed * @see #convertReportData */ public static void renderAsXls(JasperReport report, Map<String, Object> parameters, Object reportData, OutputStream stream) throws JRException { JasperPrint print = JasperFillManager.fillReport(report, parameters, convertReportData(reportData)); render(new JRXlsExporter(), print, stream); }
Example 16
Source File: JasperReportsUtils.java From spring4-understanding with Apache License 2.0 | 3 votes |
/** * Render a report in PDF format using the supplied report data. * Writes the results to the supplied {@code OutputStream}. * @param report the {@code JasperReport} instance to render * @param parameters the parameters to use for rendering * @param stream the {@code OutputStream} to write the rendered report to * @param reportData a {@code JRDataSource}, {@code java.util.Collection} or object array * (converted accordingly), representing the report data to read fields from * @param exporterParameters a {@link Map} of {@code JRExporterParameter exporter parameters} * @throws JRException if rendering failed * @see #convertReportData */ public static void renderAsPdf(JasperReport report, Map<String, Object> parameters, Object reportData, OutputStream stream, Map<net.sf.jasperreports.engine.JRExporterParameter, Object> exporterParameters) throws JRException { JasperPrint print = JasperFillManager.fillReport(report, parameters, convertReportData(reportData)); JRPdfExporter exporter = new JRPdfExporter(); exporter.setParameters(exporterParameters); render(exporter, print, stream); }
Example 17
Source File: JasperReportsUtils.java From spring4-understanding with Apache License 2.0 | 3 votes |
/** * Render a report in CSV format using the supplied report data. * Writes the results to the supplied {@code Writer}. * @param report the {@code JasperReport} instance to render * @param parameters the parameters to use for rendering * @param writer the {@code Writer} to write the rendered report to * @param reportData a {@code JRDataSource}, {@code java.util.Collection} or object array * (converted accordingly), representing the report data to read fields from * @throws JRException if rendering failed * @see #convertReportData */ public static void renderAsCsv(JasperReport report, Map<String, Object> parameters, Object reportData, Writer writer) throws JRException { JasperPrint print = JasperFillManager.fillReport(report, parameters, convertReportData(reportData)); render(new JRCsvExporter(), print, writer); }
Example 18
Source File: JasperReportsUtils.java From spring4-understanding with Apache License 2.0 | 3 votes |
/** * Render a report in HTML format using the supplied report data. * Writes the results to the supplied {@code Writer}. * @param report the {@code JasperReport} instance to render * @param parameters the parameters to use for rendering * @param writer the {@code Writer} to write the rendered report to * @param reportData a {@code JRDataSource}, {@code java.util.Collection} or object array * (converted accordingly), representing the report data to read fields from * @throws JRException if rendering failed * @see #convertReportData */ public static void renderAsHtml(JasperReport report, Map<String, Object> parameters, Object reportData, Writer writer) throws JRException { JasperPrint print = JasperFillManager.fillReport(report, parameters, convertReportData(reportData)); render(new net.sf.jasperreports.engine.export.JRHtmlExporter(), print, writer); }
Example 19
Source File: JRReportUtil.java From opencps-v2 with GNU Affero General Public License v3.0 | 2 votes |
/** * @param jrReportTemplate * @param parameters * @param dataSource * @return * @throws JRException */ protected static JasperPrint getJasperPrint(JRReportTemplate jrReportTemplate, Map<String, Object> parameters, JRJSONDataSource dataSource) throws JRException { return JasperFillManager.fillReport(jrReportTemplate, null, dataSource); }
Example 20
Source File: JRReportUtil.java From opencps-v2 with GNU Affero General Public License v3.0 | 2 votes |
/** * @param jrReportTemplate * @param parameters * @param dataSource * @return * @throws JRException */ protected static JasperPrint getJasperPrint(JasperReport jrReportTemplate, Map<String, Object> parameters, JRJSONDataSource dataSource) throws JRException { return JasperFillManager.fillReport(jrReportTemplate, null, dataSource); }