views:

19

answers:

1

I am trying to compile a sub-report from on the fly from java. I placed the subreport expression in the MAIN report as follows.

<subreportExpression class="net.sf.jasperreports.engine.JasperReport"><![CDATA[SubReportCompiler.getCompiledReport("reportId")]]></subreportExpression>

My subreportcompiler code is as follows:

public class SubReportCompiler {

private static final String JR_XML_HEADER = "<?xml version=\"1.0\" encoding=\"UTF-8\"?>"
    + "<!DOCTYPE jasperReport PUBLIC \"-//JasperReports//DTD Report Design//EN\" \"http://jasperreports.sourceforge.net/dtds/jasperreport.dtd\"&gt;";


public static JasperReport getCompiledReport(String reportId)
{

    Report report = Report.getReportObject(reportId, applicationId);

    String jasperXML=JR_XML_HEADER + report.getJASPERXML();
    InputStream jrXMLStream = new ByteArrayInputStream(jasperXML.getBytes());
    JasperReport jReport;

    try {
        jReport = JasperCompileManager.compileReport(jrXMLStream);
    } catch (JRException e) {
        throw new ReportException(e.getMessage(), e);
    }
    catch (Exception e)
    {
        throw new ReportException(e.getMessage(), e);
    }

    return jReport;
}

}

while I am trying to execute the main report from java. I am getting the following error.

(java.lang.String) No such property: SubReportCompiler for class: report2_1280833699753_269232

Do I need to register any of the properties? How to compile the subreport on the fly from java while execution of the main report?

+1  A: 

Where SubReportCompiler class is placed in? Is it placed somewhere in application Java packages? If yes, you should specify fully qualified class name in JRXML:

<subreportExpression class="net.sf.jasperreports.engine.JasperReport">
<![CDATA[mypackage.SubReportCompiler
.getCompiledReport("reportId")]]></subreportExpression>

Replace "mypackage" in the code above with your package name.

Andrey