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 (?)}" );
cs.setInt(1,70);
cs1.setInt(1,70);
rs = cs.executeQuery();
rs1 = cs1.executeQuery();
JRDataSource ds = new JRResultSetDataSource(rs);
JRDataSource ds1 = new JRResultSetDataSource(rs1);
Map<String, Object> parameters = new HashMap<String, Object>();
parameters.put("prmDs1",ds1);
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:
<detail>
<band height="83" splitType="Prevent">
<subreport>
<reportElement x="0" y="20" width="600" height="63" uuid="2ba47ed7-970d-43f8-9338-ca686c86ca18"/>
<subreportParameter name="prmCourseID">
<subreportParameterExpression><![CDATA[$F{courseID}]]></subreportParameterExpression>
</subreportParameter>
<dataSourceExpression><![CDATA[$P{prmDs1}]]></dataSourceExpression>
<subreportExpression><![CDATA["SubRptA_sub.jasper"]]></subreportExpression>
</subreport>
</band>
</detail>
How to link master and sub-report with the run-time datasource?