Hi there,
I am confused about the usage of the jasperreports' subreport. I make
a simple example, but I can't get it work. Can any expert kindly point
out how to make it work?
Here are the simple codes:
<<MainReport.xml>>:
-------------------
<?xml version="1.0"?>
<!DOCTYPE jasperReport PUBLIC "-//JasperReports//DTD Report
Design//EN" "http://jasperreports.sourceforge.net/dtds/jasperreport.dtd">
<jasperReport name="MainReport" >
<parameter name="subJrReport"
class="dori.jasper.engine.JasperReport"/>
<title>
<band height="50">
<subreport isUsingCache="true">
<reportElement x="5" y="25" width="325" height="20" />
<subreportExpression class="dori.jasper.engine.JasperReport">
<![CDATA[$P{subJrReport}]]>
</subreportExpression>
</subreport>
</band>
</title>
</jasperReport>
<<SubReport.xml>>:
------------------
<?xml version="1.0"?>
<!DOCTYPE jasperReport PUBLIC "-//JasperReports//DTD Report
Design//EN" "http://jasperreports.sourceforge.net/dtds/jasperreport.dtd">
<jasperReport name="SubReport" >
<title>
<band height="50">
<staticText>
<reportElement x="0" y="25" width="200" height="25"/>
<textElement>
<font size="10" />
</textElement>
<text><![CDATA[Shipper]]></text>
</staticText>
</band>
</title>
</jasperReport>
<<MainReportApp.java>>:
-----------------------
/*
* Created on 2004-3-30
*/
import dori.jasper.engine.design.JasperDesign;
import dori.jasper.engine.JasperReport;
import dori.jasper.engine.JasperManager;
import dori.jasper.engine.JasperPrint;
import dori.jasper.engine.JRDataSource;
import dori.jasper.engine.JREmptyDataSource;
import dori.jasper.engine.JRException;
import dori.jasper.view.JasperViewer;
import java.util.Map;
import java.util.HashMap;
/**
* @author Tony, ZHOU Jingtao
*
*/
public class MainReportApp {
public static void main(String[] args) throws JRException {
// First, load JasperDesign from XML and compile it into
JasperReport
JasperDesign jrDesign =
JasperManager.loadXmlDesign("MainReport.xml");
JasperReport jrReport = JasperManager.compileReport(jrDesign);
JasperDesign subJrDesign =
JasperManager.loadXmlDesign("SubReport.xml");
JasperReport subJrReport =
JasperManager.compileReport(subJrDesign);
// Second, create a map of parameters to pass to the report.
Map parameters = new HashMap();
parameters.put("subJrReport", subJrReport);
// Third, get a dataSource
JRDataSource jrDataSource = new JREmptyDataSource();
// Fourth, create JasperPrint using fillReport() method
JasperPrint jrPrint =
JasperManager.fillReport(jrReport, parameters, jrDataSource);
// Or to view report in the JasperViewer
JasperViewer.viewReport(jrPrint);
}
}
The result is that I always get a blank screen.
Thanks a lot!
steve - 02 Apr 2004 22:42 GMT
> Hi there,
>
[quoted text clipped - 102 lines]
>
> Thanks a lot!
send it to the author.