0

i have mainreport and subreport , where main report is getting printed in jasper, but not the subreport, see below code for subreport

<jr:list xmlns:jr="http://jasperreports.sourceforge.net/jasperreports/components" xsi:schemaLocation="http://jasperreports.sourceforge.net/jasperreports/components http://jasperreports.sourceforge.net/xsd/components.xsd" printOrder="Vertical">
                    <datasetRun subDataset="customerOrderList" uuid="38a2e0f4-ae87-42ad-b3b4-61853d9a2e23">
                        <dataSourceExpression><![CDATA[new net.sf.jasperreports.engine.data.JRBeanCollectionDataSource($F{customerOrderList})]]></dataSourceExpression>
                    </datasetRun>
                    <jr:listContents height="39" width="590">
                        <frame>
                            <reportElement x="0" y="0" width="590" height="39" uuid="609e3e45-03f6-48d0-8776-e6e393d0dbaf"/>
                            <subreport>
                                <reportElement x="0" y="0" width="590" height="39" uuid="d4ef2aed-7826-49e5-9bb1-7642cbd01279"/>
                                <subreportExpression><![CDATA["src/main/java/com/crafart/reports/customerOrders.jasper"]]></subreportExpression>
                            </subreport>
                        </frame>
                    </jr:listContents>
                </jr:list>

i have debugged the code and see there are no issues in generating the report.

i am passing customer order which contains customer details and list of orders. snippet of my customer bean

public class Customer {
    private String customerName;
    private List<Order> customerOrderList
}

and below code used to generate the report

    List<OrderDeclarationBO> orderDeclarationBOLst = new ArrayList<>();
    orderDeclarationBOLst.add(orderDeclarationBO);
    InputStream in = this.getClass().getResourceAsStream("order.jrxml");
    InputStream jasperIn = this.getClass().getResourceAsStream("order.jasper");
    JasperCompileManager.compileReport(in);
    JasperPrint jasperPrint = JasperFillManager.fillReport(jasperIn, new HashMap<String, Object>(), new JRBeanCollectionDataSource(orderDeclarationBOLst));
    JasperExportManager.exportReportToPdfFile(jasperPrint, "orderInvoice.pdf");

need help, and dont know what is still required to print subreport.

EDIT :- Adding image of the report, where i am getting null values inside sub report, and not aligned properly

enter image description here

pappu_kutty
  • 2,378
  • 8
  • 49
  • 93
  • Are you passing a datasource to your subreport? – redge Apr 24 '15 at 13:15
  • no, i am passing java bean – pappu_kutty Apr 24 '15 at 13:22
  • What section of your subreport contains the content. If it is the detail section you are not getting any because there is no data source to iterate through. – redge Apr 24 '15 at 13:25
  • i have reffered this link https://ranjitfx.wordpress.com/2010/05/18/subreport-not-displayed-in-main-jasper-report-ireport/ and made empty datasource – pappu_kutty Apr 24 '15 at 13:29
  • If your content is in the detail section then make sure it is JREmptyDataSource(1) so that there is a row to cause the iteration. – redge Apr 24 '15 at 13:31
  • after adding the empty data source, i am getting two rows, with null values. i have two list. so the data is getting printed , but now it is null – pappu_kutty Apr 24 '15 at 13:33
  • I guess you are expecting to pass the bean as a parameter. Have you actually got it assigned to the parameter? – redge Apr 24 '15 at 13:35
  • Let us [continue this discussion in chat](http://chat.stackoverflow.com/rooms/76180/discussion-between-pappu-kutty-and-redge). – pappu_kutty Apr 24 '15 at 13:36
  • I am in chat and waiting for a reply – redge Apr 24 '15 at 13:50
  • you normally need to pass everything that all reports and sub reports need to the master as parameters. You can pass a data source for the subreport as a parameter. These parameters get put in the hash map argument of the fill report method. When invoking a subreport you need to pass any parameters needed by the subreport in from the current report's parameters or from the current row of the current reports datasource. – redge Apr 24 '15 at 14:01
  • @pappu_kutty I suppose that java-**class** can't find **src**/main/java/com/crafart/reports/customerOrders.jasper. Move customerOrders.jasper into directory which near classes dir. And see this http://stackoverflow.com/questions/18656016/jasperreports-cant-locate-subreport – sanBez Apr 24 '15 at 14:50
  • That was another possibility but I thought @pappu_kutty said he had shown no problems when debugging?? – redge Apr 25 '15 at 00:44
  • yeah no issues, it is printing the subreport but all null values – pappu_kutty Apr 25 '15 at 05:14
  • 1
    It seems pappu_kutty muddle up datasource for list and subreport. List have datasource, but I don't see output fields in list. Subreport haven't dataSource (report output null values). I am don't understand the aim to use list with JRBeanCollectionDataSource($F{customerOrderList} and subreport customerOrders.jasper. Is subreport or list must show customerOrderList? – sanBez Apr 27 '15 at 07:44
  • @sanBez you got it correct, it was my mistake adding list instead of subreport, i have discovered after reffering to an example, i dont need list in main report, all i need is subreport which will have customerorderlist. the report works now – pappu_kutty Apr 27 '15 at 08:37

0 Answers0