如何在 JRBeanCollectionDataSource 上调用 *this*?

Zol*_*tán 3 list this jasper-reports

我正在将图像列表传递给我的报告。我想将其呈现在报告中的列表对象内。

我之前使用过 JasperReports 列表,并且我知道我可以使用标签引用列表中元素的每个字段$F{},但是如何引用列表本身的元素呢?

基本上我想使用类似$F{this}, 或 的东西$F{self}。有这样的事吗?

Ale*_*x K 5

是的,您可以使用别名_THIS

JasperReports 终极指南中的引用:

可以使用特殊的字段映射来访问当前的 JavaBean 对象本身。因此,当字段使用 _THIS 作为描述或名称时,数据源将返回当前 JavaBean 对象作为字段值。当报表需要从当前对象中提取一些与遵循 JavaBeans 标准的属性不对应的数据(例如,数据由带有一些参数的方法返回)时,或者当当前对象需要作为参数传递给在报表表达式之一中调用的方法。

使用_THIS的示例

jrxml文件的片段:

<subDataset name="dataset1">
    <field name="city" class="java.lang.String">
        <fieldDescription><![CDATA[_THIS]]></fieldDescription>
    </field>
</subDataset>
Run Code Online (Sandbox Code Playgroud)

JavaBean的片段:

public class AddressBean {

    private String city;
    private Integer id;
    private PersonBean person;

    public AddressBean getAddress() {
        return this;
    }

    public String getCity() {
        return city;
    }

    public Integer getId() {
        return id;
    }
Run Code Online (Sandbox Code Playgroud)

JasperReports终极指南在这里

您还可以阅读GenericJon关于How to access the root element of the datasource in jasperreports问题的答案。