public void displayReport(Filter filter, Map<String, Object> parameters) { // TODO make the report generation asynchronous and display the first page when it is ready // and not after last // page is ready currentParameters = parameters; // Load template ReportDefinition rd = (ReportDefinition) getReportSelection().getValue(); String path = getFullPath(rd); jasperReport = reportGenerator.loadTemplate(path); // Set parameters Map<String, Object> params = JRUtils.createParametersFromFilter(jasperReport, filter); params.putAll(currentParameters); currentParameters.putAll(params); // Set datasource jrDataSource = null; if (!rd.requiresDatabaseConnection()) { if (container instanceof Indexed) { jrDataSource = new JRIndexedContainerDataSource((Indexed) container); } else { jrDataSource = new JRContainerDataSource(container); } } // Generate report reportGenerator.setShowMargins(showMargins.getValue()); String html = reportGenerator.executeReportAsHtml( jasperReport, params, jrDataSource, ((WrappedHttpSession) VaadinSession.getCurrent().getSession()).getHttpSession(), VaadinSession.getCurrent().getLocale()); if (html == null || "".equals(html) || (container != null && container.size() <= 0)) { reportArea.setValue(getMessageService().getMessage(NO_DATA_FOUND_KEY)); exportPDF.setEnabled(false); } else { if (rd.requiresExternalScript()) { VaadinUtils.loadScript(REPORT_AREA_ID, html, rd.requiresExternalScript(), alreadyLoaded); // only load external script for the map alreadyLoaded = true; } else { reportArea.setValue(html); } exportPDF.setEnabled(true); } }
public void setContainer(Container container, boolean defineProperties) { this.container = container; if (defineProperties) { // Prepare the container by adding all properties needed for the reports for (ReportDefinition type : (ReportDefinition[]) reportDefinition.getClass().getEnumConstants()) { if (!type.requiresDatabaseConnection()) { JRUtils.addContainerPropertiesFromReport( container, reportGenerator.loadTemplate(getFullPath(type))); } } } }