Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsWhite Papers
Discussion GroupsFirst AidDatabasesJavaBeansGUIJava 3DVirtual MachineCORBASecurityToolsGeneral
Java DirectoryOpen Source ProjectsSample Book ChaptersUser GroupsWeb Resources
Related Topics
Databases.NETMore Topics ...

Java Forum / Tools / April 2004

Tip: Looking for answers? Try searching our database.

jasperreports subreport error

Thread view: 
ZJT - 02 Apr 2004 05:23 GMT
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.


Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.