如何将JRBeanCollectionDataSource的List传递给子报表 [英] How to pass a List of JRBeanCollectionDataSource to a subreport

查看:785
本文介绍了如何将JRBeanCollectionDataSource的List传递给子报表的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在从JRBeanCollectionDataSource生成报告。此报告是关于客户的订单。

I am generating a report from a JRBeanCollectionDataSource. This report is about a customer's order.

这是我的代码

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 采用了一个集合,这就是我所做的。

When a customer a report containing the customer details and a list of the customer orders need to be generated. Since JRBeanCollectionDataSource takes a collection, this is what i did.

Customer cust; //Customer Instance

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

JRBeanCollectionDataSource rptData = new JRBeanCollectionDataSource(custList);

如何提取 CustomerOrder 列表客户并将其作为子报告传递?

How can i extract the CustomerOrder list in Customer and pass it as a subreport?

推荐答案

你应该能够设置子报表的数据源表达式:

You should be able to set the datasource expression for the subreport:

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

生成的xml应该有一个类似于的子报告标记:

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>

您唯一需要检查的是语言报告属性设置为 Java

The only other thing you need to check is that the Language for the report properties is set to Java.

这篇关于如何将JRBeanCollectionDataSource的List传递给子报表的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆