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.