I had the same problem for more than 1 day. In the application I am developing on there are multiple JasperReports which work. I encountered this problem when adding a new one. No matter what I tried, nothing displayed in the Detail band. I tried everything from triple-checking the Controller that populates the report, to upgrading to the latest jasperreports
jar and latest iReports
version. Nothing seemed to work.
The problem is that the report is set by default to: When No Data: All Sections, No Detail
, which basically means that if no data is sent to the report, it will display all sections, except for the Detail one.
Although besides static text which I was using to test the report I was passing parameters directly from the Java Controller, it did not work until I added an EXEC [myFunction] $P{parameterId}
to the Query Text property of the report. The function is a simple straightforward one, which takes a parameterId
passed from Java as a parameter and returns something. (also, make sure you set the The language for the dataset query sql property to SQL).
To sum up, for some reason the report doesn't seem to take the Java parameters as data (so it displays all the sections, except for Detail), so when I explicitly call a SQL function which returns some parameters and put them into my detail page, it works.
I hope this helps you, I busted my head for 10 hours to figure this out.
Place your sub-report field in the any other band other than detail band and add whenNoDataType="AllSectionsNoDetail"
to your xml file.
Add it among the other report properties in <JasperReport>
tag.
You can also add using the GUI Designer.
Open your sub report and in the properties editor, at the end of the options you will find
When No Data
option. Select All Sections with No Detail
from the list of available options.
Mainreport :
<?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="report1" pageWidth="595" pageHeight="842" columnWidth="555" leftMargin="20" rightMargin="20" topMargin="20" bottomMargin="20">
<property name="ireport.zoom" value="1.0"/>
<property name="ireport.x" value="0"/>
<property name="ireport.y" value="12"/>
<parameter name="SUBREPORT_DIR" class="java.lang.String" isForPrompting="false">
<defaultValueExpression><![CDATA["/home/qualian/Desktop/gopi/prjreport/"]]></defaultValueExpression>
</parameter>
<queryString>
<![CDATA[]]>
</queryString>
<background>
<band splitType="Stretch"/>
</background>
<title>
<band height="79" splitType="Stretch"/>
</title>
<pageHeader>
<band height="35" splitType="Stretch"/>
</pageHeader>
<columnHeader>
<band height="61" splitType="Stretch"/>
</columnHeader>
<detail>
<band height="125" splitType="Stretch">
<subreport>
<reportElement x="33" y="56" width="208" height="36"/>
<connectionExpression><![CDATA[$P{REPORT_CONNECTION}]]></connectionExpression>
<subreportExpression class="java.lang.String"><![CDATA[$P{SUBREPORT_DIR}+"report3_subreport1.jasper"]]></subreportExpression>
</subreport>
<staticText>
<reportElement x="33" y="15" width="100" height="20"/>
<textElement/>
<text><![CDATA[Main Report]]></text>
</staticText>
</band>
</detail>
<columnFooter>
<band height="45" splitType="Stretch"/>
</columnFooter>
<pageFooter>
<band height="54" splitType="Stretch"/>
</pageFooter>
<summary>
<band height="42" splitType="Stretch"/>
</summary>
Sub report:
<?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="report1_subreport3" language="groovy" pageWidth="555" pageHeight="802" whenNoDataType="AllSectionsNoDetail" columnWidth="555" leftMargin="0" rightMargin="0" topMargin="0" bottomMargin="0">
<property name="ireport.zoom" value="1.0"/>
<property name="ireport.x" value="0"/>
<property name="ireport.y" value="0"/>
<background>
<band splitType="Stretch"/>
</background>
<columnHeader>
<band height="40" splitType="Stretch">
<staticText>
<reportElement x="107" y="12" width="100" height="20"/>
<textElement/>
<text><![CDATA[Sub Report]]></text>
</staticText>
</band>
</columnHeader>
This worked like a charm. Hope this helps.
Best Answer
I fixed the problem, so I thought I'd post my solution here in case someone found it useful.
Things to check:
In my case, I had made a subreport and passed it a datasource that I wasn't actually using (it was an informational subreport not using any data from the datasource).
(the example is an XML datasource but the same concept applies to SQL datasources.)
e.g.
Later, the "Note" was turned into an array instead of a single note. Which meant my footer-subreport was trying to repeat twice, thus the footer report was printing twice, making it too high. Thus the error.