jcwy Posted September 15, 2020 Share Posted September 15, 2020 Master record: Course ID, Course NameDetail record (in sub-report): Course ID (Key to link with Master record), Student ID, Student NameExample of output:Course ID: A001Course Name: Course AStudent ID Student NameSA001 DavidSA002 MarinaCourse ID: B001Course Name: Course BStudent ID Student NameSB001 AlbertSB002 JessHow 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? Link to comment Share on other sites More sharing options...
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now