开发者

How to compile a subreport while the main report is executing in ireport?

开发者 https://www.devze.com 2023-01-10 05:02 出处:网络
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.

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\">";


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?


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.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号