I'm having trouble generating a basic report (master/subreport) with JavaBeans in Jaspersoft Studio.
I created TestMainReport.jrxml and TestSubreport.jrxml.
TestMainReport.jrxml contains two static text fields, labeled "A Title" in the title band and "A Summary" in the summary band.
TestSubreport.jrxml contains two static text fields, "Subreport Title" in the title and "Subreport Summary" in the summary band.
I've assigned JavaBeans Data Adapters to them, which are not used (although the JavaBean fields are being mapped in the master report. I just happened to not map them in the subreport since they are not used).
A subreport element has been added to the master report in the Summary band.
Both reports are well generated individually when I try to generate each one. However, the subreport static texts won't appear in the master report.
I was expecting that the subreport's static texts would appear in the master report.
What am I doing wrong?
TestMainReport.jrxml
<?xml version="1.0" encoding="UTF-8"?>
<jasperReport xmlns="http://jasperreports.sourceforge.net/jasperreports" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://jasperreports.sourceforge.net/jasperreports http://jasperreports.sourceforge.net/xsd/jasperreport.xsd" name="TestMainReport" pageWidth="595" pageHeight="842" columnWidth="555" leftMargin="20" rightMargin="20" topMargin="20" bottomMargin="20" uuid="0d969cfb-66d2-442f-b7a4-5a9e1a40c3ae">
<property name="com.jaspersoft.studio.data.defaultdataadapter" value="Customer Info Data Adapter"/>
<field name="birthday" class="java.time.LocalDate">
<fieldDescription><![CDATA[birthday]]></fieldDescription>
</field>
<field name="observacao" class="java.lang.String">
<fieldDescription><![CDATA[observacao]]></fieldDescription>
</field>
<field name="orderNumber" class="java.lang.Integer">
<fieldDescription><![CDATA[orderNumber]]></fieldDescription>
</field>
<field name="phone" class="java.lang.String">
<fieldDescription><![CDATA[phone]]></fieldDescription>
</field>
<field name="name" class="java.lang.String">
<fieldDescription><![CDATA[name]]></fieldDescription>
</field>
<field name="email" class="java.lang.String">
<fieldDescription><![CDATA[email]]></fieldDescription>
</field>
<title>
<band height="79" splitType="Stretch">
<staticText>
<reportElement x="0" y="0" width="100" height="30" uuid="db07ac65-15f6-4190-b1db-9d445456f306"/>
<text><![CDATA[A Title]]></text>
</staticText>
</band>
</title>
<summary>
<band height="215" splitType="Stretch">
<staticText>
<reportElement x="0" y="0" width="100" height="30" uuid="08c03e87-2b15-4eb1-b404-b7dce6dfb890"/>
<text><![CDATA[A Summary]]></text>
</staticText>
<subreport>
<reportElement x="0" y="30" width="560" height="150" uuid="c292246e-1ffa-4f08-a783-a0b05b28be76"/>
<connectionExpression><![CDATA[$P{REPORT_CONNECTION}]]></connectionExpression>
<subreportExpression><![CDATA["TestSubreport.jasper"]]></subreportExpression>
</subreport>
</band>
</summary>
</jasperReport>
TestSubreport.jrxml
<?xml version="1.0" encoding="UTF-8"?>
<jasperReport xmlns="http://jasperreports.sourceforge.net/jasperreports" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://jasperreports.sourceforge.net/jasperreports http://jasperreports.sourceforge.net/xsd/jasperreport.xsd" name="TestSubreport" pageWidth="595" pageHeight="842" columnWidth="555" leftMargin="20" rightMargin="20" topMargin="20" bottomMargin="20" uuid="d5dd9821-786d-4312-81c9-fd77f1abfb8a">
<property name="com.jaspersoft.studio.data.defaultdataadapter" value="Customer Addresses Data Adapter"/>
<title>
<band height="79" splitType="Stretch">
<staticText>
<reportElement x="0" y="0" width="100" height="30" uuid="4c9fdc83-4039-4eed-b593-448898853071"/>
<text><![CDATA[Subreport Title]]></text>
</staticText>
</band>
</title>
<summary>
<band height="42" splitType="Stretch">
<staticText>
<reportElement x="0" y="0" width="100" height="30" uuid="4bb9ba45-548a-4e87-a543-472b0f960487"/>
<text><![CDATA[Subreport Summary]]></text>
</staticText>
</band>
</summary>
</jasperReport>
CustomerInfoDataSource.java
package testdatasource;
import java.time.LocalDate;
import java.util.ArrayList;
import java.util.Collection;
import java.util.List;
public class CustomerInfoDataSource {
public static Collection<CustomerInfo> getCustomerInfo() {
List<CustomerInfo> info = new ArrayList<>();
info.add(new CustomerInfo(1, "Mario", "[email protected]", LocalDate.now(), "14 912345678", "Observação Mario"));
return info;
}
}
CustomerInfo.java
package testdatasource;
import java.time.LocalDate;
public class CustomerInfo {
private final int orderNumber;
private final String name;
private final String email;
private final LocalDate birthday;
private final String phone;
private final String observacao;
public CustomerInfo(int orderNumber, String name, String email, LocalDate birthday, String phone, String observacao) {
this.orderNumber = orderNumber;
this.name = name;
this.email = email;
this.birthday = birthday;
this.phone = phone;
this.observacao = observacao;
}
public int getOrderNumber() {
return orderNumber;
}
public String getName() {
return name;
}
public String getEmail() {
return email;
}
public LocalDate getBirthday() {
return birthday;
}
public String getPhone() {
return phone;
}
public String getObservacao() {
return observacao;
}
}
CustomerAddressDataSource.java
package testdatasource;
import java.util.ArrayList;
import java.util.Collection;
import java.util.List;
public class CustomerAddressDataSource {
public static Collection<CustomerAddress> getCustomerAddresses() {
List<CustomerAddress> addresses = new ArrayList<>();
addresses.add(new CustomerAddress("Casa 1", "Rua Tal", "123", null, "Jardim Márcia", "Agudos", "17400-000", "Perto da caixa d'água"));
addresses.add(new CustomerAddress("Casa 2", "Rua Tal", "456", null, "Jardim Márcia", "Agudos", "17400-000", "Perto da caixa d'água"));
return addresses;
}
}
CustomerAddress.java
package testdatasource;
public class CustomerAddress {
private final String title;
private final String street;
private final String number;
private final String complement;
private final String bairro;
private final String city;
private final String cep;
private final String referencePoint;
public CustomerAddress(String title, String street, String number, String complement, String bairro, String city,
String cep, String referencePoint) {
this.title = title;
this.street = street;
this.number = number;
this.complement = complement;
this.bairro = bairro;
this.city = city;
this.cep = cep;
this.referencePoint = referencePoint;
}
public String getTitle() {
return title;
}
public String getStreet() {
return street;
}
public String getNumber() {
return number;
}
public String getComplement() {
return complement;
}
public String getBairro() {
return bairro;
}
public String getCity() {
return city;
}
public String getCep() {
return cep;
}
public String getReferencePoint() {
return referencePoint;
}
}
Output from TestMainReport.jrxml:
Output from TestSubreport.jrxml:




any tips in how to locate it in a search?- It is hard to answer, if you know what to find - you have an advantage :). I think the good workflow for searching something about JR is: "Look at JasperReports-Ultimate-Guide" -> "Look at Sample Reference (jasperreports.sourceforge.net/sample.reference.html)" -> "Look at JSS help" -> "Search at SO/community.jaspersoft.com". I added some usefull links at my post. - Alex K