简体   繁体   English

在ireport中执行主报表时,如何编译子报表?

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

I am trying to compile a sub-report from on the fly from java. 我正在尝试从Java动态编译子报告。 I placed the subreport expression in the MAIN report as follows. 我将子报表表达式放在MAIN报告中,如下所示。

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

My subreportcompiler code is as follows: 我的subreportcompiler代码如下:

public class SubReportCompiler { 公共类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. 当我尝试从Java执行主要报告时。 I am getting the following error. 我收到以下错误。

(java.lang.String) No such property: SubReportCompiler for class: report2_1280833699753_269232 (java.lang.String)没有这样的属性:SubReportCompiler类: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? 如何在执行主报表时从Java即时编译子报表?

Where SubReportCompiler class is placed in? SubReportCompiler类放在哪里? Is it placed somewhere in application Java packages? 它放置在应用程序Java包中的某个位置吗? If yes, you should specify fully qualified class name in JRXML: 如果是,则应在JRXML中指定完全限定的类名:

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

Replace "mypackage" in the code above with your package name. 用您的程序包名称替换上面代码中的“ mypackage”。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM