如何JRBeanCollectionDataSource的列表传递给子报表(How to pass

2019-07-03 19:42发布

我生成从JRBeanCollectionDataSource的报告。 这份报告是关于一个客户的订单。

这是我的代码

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
}

当要产生客户包含客户详细信息和客户订单列表的报告需要。 由于JRBeanCollectionDataSource需要收集,这是我做的。

Customer cust; //Customer Instance

ArrayList<Customer> custList = new ArrayList<Customer>();
custList.add(cust); 

JRBeanCollectionDataSource rptData = new JRBeanCollectionDataSource(custList);

我怎样才能提取CustomerOrder名单中Customer ,并把它作为一个子报表?

Answer 1:

您应该能够设置数据源表达的报表:

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

生成的XML应该有一个类似于报表标签:

<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>

你需要检查的唯一的另一件事是, Language的报表属性设置为Java



文章来源: How to pass a List of JRBeanCollectionDataSource to a subreport