如何在iReport中打印另一个列表中包含的字符串列表? [英] How do I print a list of strings contained within another list in iReport?

查看:357
本文介绍了如何在iReport中打印另一个列表中包含的字符串列表?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在创建一个简单的报告程序,使用java和iReport(来自jasper),它应该用pdf创建一个报告,显示PC的IP地址,位置,此时是否空闲(由另一个人处理)系统),以及它当前附加到的项目列表(也在其他地方管理)。

I am creating a simple reporting program using java and iReport (from jasper), which is supposed to create a report in pdf showing PCs with their IP address, their location, whether it's idle or not at the moment (handled by another system), and a list of projects it is currently attached to (managed elsewhere, too).

我正在使用iReport这个问题,并创建了一个虚拟集合生成类如下:

I'm using iReport for this matter, and have created a dummy collection generating class as follows:

public class PCReports {

    public static java.util.Collection PC_collection;
    public static java.util.Collection generateCollection() {

        PC_collection = new ArrayList<PCLineDTO>();
        PCLineDTO line = new PCLineDTO();
        line.setIP("192.168.1.1");
        line.setLab("location");
        line.setActive(true);
        line.addProjectName("project1");
        line.addProjectName("project2");
        line.addProjectName("project3");
        PC_collection.add(line);

        line = new PCLineDTO();
        line.setIp("192.168.1.2");
        line.setLab("location2");
        line.setActive(false);
        line.addProjectName("project1");
        line.addProjectName("project2");
        PC_collection.add(line);

        return PC_collection;
    }
}

在这种情况下,实体类是:

The entity class in this case being:

public class PCLineDTO {
    private String ip;
    private String lab;
    private Boolean active;
    private ArrayList<String> projects;
}

在网上搜索一遍后,我发现一种类似的方法

After some searching around the Internet, I found a way to do something similar, using subreports.

问题是,我不知道如何打印作为dataSource传递给该子报告的字符串集合。

The thing is, I don't know how to print a collection of strings passed as a dataSource to this subreport.

在我在Internet上找到的示例中,对于主集合中的每个项目,子报表都传递了一组对象 - 每个属性都有自己的getter方法 - 而不是集合像字符串这样的情况。在这些情况下,他们通过我无法使用的iReport语法访问他们需要使用的值,例如:

In the examples I found on the Internet, for each item in the master collection, the subreports were passed a collection of objects -with their own getter methods for each attribute- instead of a collection of strings as is the case here. In those cases, they accessed the values they needed to use via the iReport syntax, which I was not able to use, for example:

$F{project}

由于iReport查找收到的对象中包含的getProject方法,但在这种情况下,它是一个简单的String对象(没有getProject方法,因为它)。

Since iReport looks for a getProject method contained within the objects it receives, but in this case it's a simple String object (without a getProject method, as it were).

推荐答案

使用子报表或子数据集。

Use a subreport or a subdataset.

传递报表的集合数据源

JRBeanCollectionDataSource($F{Projects})

然后在新的子报告中创建一个名为_THIS的新字段,这个表示传递的集合中的bean与我想要的值相同

Then in the new subreport create a new field called "_THIS" exactly, this means the bean in the collection passed is the same as the value i want

有关详细信息,请在此处检查类的源代码: JRAbstractBeanDataSource

For more info, check the source code of the class here: JRAbstractBeanDataSource

注意:这是在可用的JasperReport 3.0.0我不确定它是否存在于以前的版本中。
希望这有帮助

Note: this is available in JasperReport 3.0.0 im not sure if it exists in previous builds. Hope this helps

更新:刚检查过SVN,好像这个功能在JasperReports 2.0.0中实现

Update: just checked the SVN, seems like this feature is implemented in JasperReports 2.0.0

这篇关于如何在iReport中打印另一个列表中包含的字符串列表?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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