Jasper报告中Java Beans列表中的传递列表 [英] pass list in Java Beans List in Jasper Report

查看:62
本文介绍了Jasper报告中Java Beans列表中的传递列表的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在将Jasper Report与Servlet一起使用. Team Bean看起来像

I am using Jasper Report with Servlet. Team Bean looks like

private int tid;
private String title;
private List<Member> members;
//getter and setter

成员豆看起来像

private int id;
private String name;
//getter and setter

在报告Servlet中,

In report Servlet,

 List<Team> teams = service.getTeams();
 Map parameters = new HashMap();
 JasperPrint jasperPrint = null;
 jasperPrint  = JasperFillManager.fillReport(jasperReport, parameters, new JRBeanCollectionDataSource(teams));

在新的JRBeanCollectionDataSource(teams)中添加团队时,如何在Jasper报表中显示它?因为它在列表中包含列表.

When add teams in new JRBeanCollectionDataSource(teams), how can I show it in Jasper report? Because it contains List in the List.

我需要子报表来解决此问题吗?

Do I need subreport to solve this problem?

或者我可以在没有子报表的情况下解决这个问题吗?

Or can I solve this without subreport?

推荐答案

有两种方法可以实现此目的:

There are two ways that you can accomplish this:

您确实可以通过使用子报告来解决此问题.为此,您需要添加一个子报表并将其数据源表达式设置为new JRBeanCollectionDataSource($F{members}).这样,您的Member bean的字段就可以用作子报表中的字段(例如$F{name}).

You can indeed solve this by using a subreport. To do that you would need to add a subreport and set its datasource expression to new JRBeanCollectionDataSource($F{members}). The fields of your Member bean would then be available as fields in the subreport (e.g. $F{name}).

您还可以通过使用列表组件来解决此问题而无需子报告.可以从iReport的调色板中获得,也可以复制以下示例.这需要添加到报告的明细栏中.

You can also solve this without a subreport by using a list component. This is available from the palette in iReport, or you can copy the example below. This needs to be added to the detail band of your report.

列表组件具有与报表一样的数据源表达式,应将其设置为new JRBeanCollectionDataSource($F{members}),并且具有listContents元素,其行为类似于子报表的详细信息带.其中的元素将对数据源中的每个成员重复一次.

The list component has a datasource expression just like a report, which you should set to new JRBeanCollectionDataSource($F{members}), and has a listContents element that behaves like the detail band of a subreport; the elements inside it will be repeated once for every member in the datasource.

列表组件在您的报表中需要一个子数据集,但是iReport会自动添加该子数据集,或者您可以轻松地添加一个空的子数据集:<subDataset name="dataset1"/>.

The list component requires a subdataset in your report, but this will be added automatically by iReport, or you can easily add an empty one: <subDataset name="dataset1"/>.

<componentElement>
    <reportElement x="0" y="0" width="555" height="20"/>
        <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">
        <datasetRun subDataset="dataset1">
            <dataSourceExpression><![CDATA[new JRBeanCollectionDataSource($F{members})]]></dataSourceExpression>
        </datasetRun>
        <jr:listContents height="20" width="555">
            <textField>
                <reportElement x="0" y="0" width="100" height="20"/>
                <textElement/>
                <textFieldExpression><![CDATA[$F{name}]]></textFieldExpression>
            </textField>
        </jr:listContents>
    </jr:list>
</componentElement>

有关列表组件的更多信息,请参见: http://jasperreports. sourceforge.net/sample.reference/list/index.html

More information on the list component is available here: http://jasperreports.sourceforge.net/sample.reference/list/index.html

这篇关于Jasper报告中Java Beans列表中的传递列表的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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