3

I am passing a list of images to my report. I want to render it inside a List object in the report.

I have used JasperReports lists before and I'm aware that I can reference each field of an element in a list using the $F{} tag, but how can I reference the element of the list itself?

Basically i would like to use something like $F{this}, or $F{self}. Is there such a thing?

Zoltán
  • 21,321
  • 14
  • 93
  • 134
  • 1
    The quote from *JasperReports Ultimate Guide*: `A special field mapping can be used to access the current JavaBean object itself. Thus, when a field uses _THIS as description or name, the data source will return the current JavaBean object as field value. This is useful when the report needs to extract from the current object some data that does not correspond to a property that follows JavaBeans standards (for instance, the data is returned by a method that takes some arguments), or when the current object needs to be passed to as argument to a method called in one of the report expressions.` – Alex K May 14 '13 at 12:30
  • The [JasperReports Ultimate Guide](http://jasperreports.sourceforge.net/JasperReports-Ultimate-Guide-3.pdf) is very useful – Alex K May 14 '13 at 12:32
  • Indeed. I passed over that paragraph, but missed it. Add your comment as an answer and I will accept it. – Zoltán May 14 '13 at 12:42

1 Answers1

4

Yes, you can use the alias _THIS.

The quote from the JasperReports Ultimate Guide:

A special field mapping can be used to access the current JavaBean object itself. Thus, when a field uses _THIS as description or name, the data source will return the current JavaBean object as field value. This is useful when the report needs to extract from the current object some data that does not correspond to a property that follows JavaBeans standards (for instance, the data is returned by a method that takes some arguments), or when the current object needs to be passed to as argument to a method called in one of the report expressions.

The sample of using _THIS

The snippet of jrxml file:

<subDataset name="dataset1">
    <field name="city" class="java.lang.String">
        <fieldDescription><![CDATA[_THIS]]></fieldDescription>
    </field>
</subDataset>

The snippet of 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;
    }

The JasperReports Ultimate Guide is here.

You can also read the answer by GenericJon on How to access the root element of the datasource in jasperreports question.

Community
  • 1
  • 1
Alex K
  • 22,315
  • 19
  • 108
  • 236
  • TIBCO Jaspersoft Studio (all 6.* variants) complicates things a little bit. It doesn't recognize the field when the description has **"<![CDATA[ ]"** and doesn't let you change the jxml file in source mode. – Gilberto Nov 06 '19 at 12:12