How to pass a JRBeanCollectionDataSource list to a subtitle

I am creating a report from JRBeanCollectionDataSource. This report is about a sales order.

This is my code.

public class Customer { private String customerName; private String customerNo; private String customerAddress; private ArrayList<CustomerOrder> customerOrders; //Getters and Setters } private class CustomerOrder { private String itemName; private BigDecimal amount; private int itemQuantity; //Getters and Setters } 

When a customer must create a report containing customer information and a list of customer orders. Since the JRBeanCollectionDataSource takes the collection, this is what I did.

 Customer cust; //Customer Instance ArrayList<Customer> custList = new ArrayList<Customer>(); custList.add(cust); JRBeanCollectionDataSource rptData = new JRBeanCollectionDataSource(custList); 

How can I retrieve the CustomerOrder list in Customer and pass it as a subreport?

+4
source share
1 answer

You should be able to set the data source expression for the subreport:

 new net.sf.jasperreports.engine.data.JRBeanCollectionDataSource($F{customerOrders}) 

The resulting xml should have a subreport tag that resembles:

 <subreport> <reportElement uuid="e9fc4a60-3844-41b7-a38c-768f06f09b44" x="0" y="57" width="555" height="68"/> <dataSourceExpression><![CDATA[new net.sf.jasperreports.engine.data.JRBeanCollectionDataSource($F{customerOrders})]]></dataSourceExpression> <subreportExpression><![CDATA[$P{SUBREPORT_DIR} + "report2_subreport1.jasper"]]></subreportExpression> </subreport> 

The only thing you need to check is that the Language report property is set to Java .

+8
source

Source: https://habr.com/ru/post/1446064/


All Articles