JasperReport Master-Details report with sub-report

Master record: Course ID, Course Name
Detail record (in sub-report): Course ID (Key to link with Master record), Student ID, Student Name

Example of output:

Course ID: A001
Course Name: Course A
Student ID Student Name
SA001 David
SA002 Marina

Course ID: B001
Course Name: Course B
Student ID Student Name
SB001 Albert
SB002 Jess

How should I design the report and code it? Want to get an idea to design such master-detail report using sub-report instead of grouping.

There are examples of doing this by writing the sql for sub-report with the passing-in parameter, for example:

select * from Table A where courseID = $P!{courseID}

My problem is both the datasource for master and detail report are generated at runtime, for example in my jsp coding:

cs = conn.prepareCall( "{call spTestJasperA (?)}" );
cs1 = conn.prepareCall( "{call spTestJasperB (?)}" );
rs = cs.executeQuery();
rs1 = cs1.executeQuery();
JRDataSource ds = new JRResultSetDataSource(rs);
JRDataSource ds1 = new JRResultSetDataSource(rs1);

Map<String, Object> parameters = new HashMap<String, Object>();
ServletContext context = request.getServletContext();
String s = context.getRealPath("/SubRptA.jasper");
File reportFile = new File(s);
byte[] bytes = JasperRunManager.runReportToPdf(reportFile.getPath(), parameters, ds);

In Master.jrxml:
<band height="83" splitType="Prevent">
        <reportElement x="0" y="20" width="600" height="63" uuid="2ba47ed7-970d-43f8-9338-ca686c86ca18"/>
        <subreportParameter name="prmCourseID">

How to link master and sub-report with the run-time datasource?

jcwy's picture
Joined: Jul 8 2012 - 7:27pm
Last seen: 3 years 5 days ago

0 Answers:

No answers yet