Hi,
How would you embed the HTML content from an HTML-based Jasper report into JSP?
I am trying to do the following:
1. Create a Jasper report template.
2. Generate an HTML version of the report (using parameters).
3. Embed the HTML content within the JSP.
I would rather not generate an image for the report. I may not create a pop-up window for the HTML report. I may not generate a PDF. The report must be embedded into a regular JSP (for various reasons).
I have tried something like this:
<af:outputText value="#{backing_HTMLReport.run}"/>
The backing bean's
run method would be similar to:
public String run() {
JRExporter exporter = getExporter();
Connection connection = getConnection();
InputStream template = getTemplateSource();
StringWriter destination = new StringWriter();
Map parameters = getReportParameters();
JasperPrint print = JasperFillManager.fillReport(template, parameters, connection);
exporter.setParameter(JRExporterParameter.JASPER_PRINT, print);
exporter.setParameter(JRExporterParameter.OUTPUT_WRITER, destination);
exporter.exportReport();
return extractReportContents( destination.getBuffer() );
}
public JRExporter getExporter() {
return new JRHtmlExporter();
}
The
extractReportContents method would trim the report of redundant tags (e.g., <html>, <head>, and <body> tags).
The result would be that the report runs, writes the HTML page into a StringBuffer, then includes the content of that StringBuffer into the JSP itself.
This doesn't quite work. I need a way to embed arbitrary HTML content into the JSP.
Thoughts?
D