How to use the same REPORT_COUNT in multiple tables incrementing it? - jasper-reports

I'm using iReport 5.6 to generate reports for my JavaApp, I have three datasets where as bellow :
dataset1 query
SELECT * FROM players s WHERE s.role = 1
dataset2 query
SELECT * FROM players s WHERE s.role = 2
dataset3 query
SELECT * FROM players s WHERE s.role = 3
then I have created 3 Detail bands where I have put :
Detail 1 contains table1 that uses dataset1 : in this table I defined the headers that are the same for the other tables (2 and 3)
Detail 2 contains table2 that uses dataset2
Detail 3 contains table3 that uses dataset3
What I can't do is to add a count column using the $V{REPORT_COUNT} jasper variable for the three table that doesn't refresh the counting as I want this counting to continue the incrementation.

To achieve this you can use the possibility to specify returnValue from datasetRun (table) and then pass this to next datasetRun (table) as a datasetParameter
In example we will pass as returnValue the $V{REPORT_COUNT} (of the table) to a variabile in main report $V{currentRecordCnt}, the currentRecordCnt we will then pass to next datasetRun (table 2) and use this to increment a variabile in 2 dataset
<variable name="accRecordCnt" class="java.lang.Integer">
<variableExpression><![CDATA[$P{currentRecordCnt}+$V{REPORT_COUNT}]]></variableExpression>
</variable>
We then pass the accRecordCnt back to main report's currentRecordCnt and repeat same for table 3.
Full jrxml example
<?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="AccuSum" pageWidth="595" pageHeight="842" whenNoDataType="AllSectionsNoDetail" columnWidth="555" leftMargin="20" rightMargin="20" topMargin="20" bottomMargin="20" uuid="85a44d77-bc70-4059-a88a-60aca0ef6bf0">
<property name="com.jaspersoft.studio.data.defaultdataadapter" value="One Empty Record"/>
<subDataset name="Dataset1" uuid="5a00c263-2028-4446-948e-d614136ec5d7">
<queryString>
<![CDATA[]]>
</queryString>
</subDataset>
<subDataset name="Dataset2" uuid="3ff8e779-2e60-403c-81f8-1d20fd04fc78">
<parameter name="currentRecordCnt" class="java.lang.Integer"/>
<queryString>
<![CDATA[]]>
</queryString>
<variable name="accRecordCnt" class="java.lang.Integer">
<variableExpression><![CDATA[$P{currentRecordCnt}+$V{REPORT_COUNT}]]></variableExpression>
</variable>
</subDataset>
<subDataset name="Dataset3" uuid="3ff8e779-2e60-403c-81f8-1d20fd04fc78">
<parameter name="currentRecordCnt" class="java.lang.Integer"/>
<queryString>
<![CDATA[]]>
</queryString>
<variable name="accRecordCnt" class="java.lang.Integer">
<variableExpression><![CDATA[$P{currentRecordCnt}+$V{REPORT_COUNT}]]></variableExpression>
</variable>
</subDataset>
<queryString>
<![CDATA[]]>
</queryString>
<variable name="currentRecordCnt" class="java.lang.Integer"/>
<detail>
<band height="54" splitType="Stretch">
<componentElement>
<reportElement x="0" y="10" width="540" height="30" uuid="c46d16ff-7b32-4481-8d89-0435f34f7b32">
<property name="com.jaspersoft.studio.layout" value="com.jaspersoft.studio.editor.layout.VerticalRowLayout"/>
</reportElement>
<jr:table xmlns:jr="http://jasperreports.sourceforge.net/jasperreports/components" xsi:schemaLocation="http://jasperreports.sourceforge.net/jasperreports/components http://jasperreports.sourceforge.net/xsd/components.xsd">
<datasetRun subDataset="Dataset1" uuid="6b893feb-3e07-4393-ae4d-30b64e3dbaf5">
<dataSourceExpression><![CDATA[new net.sf.jasperreports.engine.JREmptyDataSource(5)]]></dataSourceExpression>
<returnValue fromVariable="REPORT_COUNT" toVariable="currentRecordCnt"/>
</datasetRun>
<jr:column width="160" uuid="3b6f8589-0c6d-4709-a8cd-6cf642fd4ec9">
<jr:detailCell height="30">
<textField>
<reportElement x="0" y="0" width="160" height="30" uuid="a04fcd2b-e179-4fdb-8eac-31da14721c9a"/>
<textFieldExpression><![CDATA[$V{REPORT_COUNT}]]></textFieldExpression>
</textField>
</jr:detailCell>
</jr:column>
</jr:table>
</componentElement>
</band>
<band height="50">
<componentElement>
<reportElement x="0" y="10" width="540" height="30" uuid="6866e777-15b8-49a7-b00f-3ce3593c16c0">
<property name="com.jaspersoft.studio.layout" value="com.jaspersoft.studio.editor.layout.VerticalRowLayout"/>
</reportElement>
<jr:table xmlns:jr="http://jasperreports.sourceforge.net/jasperreports/components" xsi:schemaLocation="http://jasperreports.sourceforge.net/jasperreports/components http://jasperreports.sourceforge.net/xsd/components.xsd">
<datasetRun subDataset="Dataset2" uuid="f71b2649-27c0-4a30-bb68-8bc7c8a26100">
<datasetParameter name="currentRecordCnt">
<datasetParameterExpression><![CDATA[$V{currentRecordCnt}]]></datasetParameterExpression>
</datasetParameter>
<dataSourceExpression><![CDATA[new net.sf.jasperreports.engine.JREmptyDataSource(5)]]></dataSourceExpression>
<returnValue fromVariable="accRecordCnt" toVariable="currentRecordCnt"/>
</datasetRun>
<jr:column width="160" uuid="6e116b9f-cf9f-4a27-9e9a-892263482caf">
<property name="com.jaspersoft.studio.components.table.model.column.name" value="Column1"/>
<jr:detailCell height="30">
<textField>
<reportElement x="0" y="0" width="160" height="30" uuid="8cb085f1-5155-4b17-9304-c3bb616ac965"/>
<textFieldExpression><![CDATA[$V{accRecordCnt}]]></textFieldExpression>
</textField>
</jr:detailCell>
</jr:column>
</jr:table>
</componentElement>
</band>
<band height="50">
<componentElement>
<reportElement x="0" y="10" width="540" height="30" uuid="338527a7-5c7e-419d-ac85-658ac2d30655">
<property name="com.jaspersoft.studio.layout" value="com.jaspersoft.studio.editor.layout.VerticalRowLayout"/>
</reportElement>
<jr:table xmlns:jr="http://jasperreports.sourceforge.net/jasperreports/components" xsi:schemaLocation="http://jasperreports.sourceforge.net/jasperreports/components http://jasperreports.sourceforge.net/xsd/components.xsd">
<datasetRun subDataset="Dataset3" uuid="8c00ef2e-d328-42a8-8ba5-12bfde8225c0">
<datasetParameter name="currentRecordCnt">
<datasetParameterExpression><![CDATA[$V{currentRecordCnt}]]></datasetParameterExpression>
</datasetParameter>
<dataSourceExpression><![CDATA[new net.sf.jasperreports.engine.JREmptyDataSource(5)]]></dataSourceExpression>
</datasetRun>
<jr:column width="160" uuid="7e28ae8d-b64b-42fa-a5eb-4213198d1341">
<property name="com.jaspersoft.studio.components.table.model.column.name" value="Column1"/>
<jr:detailCell height="30">
<textField>
<reportElement x="0" y="0" width="160" height="30" uuid="05900214-f740-4742-bae3-f4a97aed073e"/>
<textFieldExpression><![CDATA[$V{accRecordCnt}]]></textFieldExpression>
</textField>
</jr:detailCell>
</jr:column>
</jr:table>
</componentElement>
</band>
</detail>
</jasperReport>
Output (with 1 empty record)

Related

JasperReport: Unexpected White Space Between <jr:listContents> Elements

Hitting quite the roadblock on this one. I have a primary report which loads a subreport. Said subreport contains nested lists, of which the inner list is rendering some unexpected white space between elements. The white space is consistent in size, which almost seems as if the report is rendering a "ghost" element.
Relevant jrxml for reference:
<subDataset name="SurveyListDataSet">
<property name="com.jaspersoft.studio.data.defaultdataadapter" />
<queryString><![CDATA[]]></queryString>
<field name="surveyDate" class="java.lang.String"/>
<field name="surveyList" class="java.util.List"/>
</subDataset>
<subDataset name="SurveyDataSet">
<property name="com.jaspersoft.studio.data.defaultdataadapter" />
<queryString><![CDATA[]]></queryString>
<field name="question" class="java.lang.String"/>
<field name="response" class="java.lang.String"/>
</subDataset>
<field name="surveyDataList" class="java.util.List"/>
<detail>
<band height="17" splitType="Stretch">
<componentElement>
<reportElement x="0" y="0" width="505" height="17" isRemoveLineWhenBlank="true" />
<jr:list xmlns:jr="http://jasperreports.sourceforge.net/jasperreports/components" xsi:schemaLocation="http://jasperreports.sourceforge.net/jasperreports/components http://jasperreports.sourceforge.net/xsd/components.xsd" printOrder="Vertical">
<datasetRun subDataset="SurveyListDataSet">
<dataSourceExpression><![CDATA[new net.sf.jasperreports.engine.data.JRBeanCollectionDataSource($F{surveyDataList})]]></dataSourceExpression>
</datasetRun>
<jr:listContents height="17" width="505">
<textField isStretchWithOverflow="true">
<reportElement style="report_value_bold" x="110" y="0" width="265" height="15" />
<textElement textAlignment="Left" />
<textFieldExpression><![CDATA[$F{surveyDate}]]></textFieldExpression>
</textField>
<line>
<reportElement style="line_light" x="105" y="16" width="400" height="1"/>
</line>
<componentElement>
<reportElement x="0" y="0" width="505" height="0" isRemoveLineWhenBlank="true" positionType="Float"/>
<jr:list xmlns:jr="http://jasperreports.sourceforge.net/jasperreports/components" xsi:schemaLocation="http://jasperreports.sourceforge.net/jasperreports/components http://jasperreports.sourceforge.net/xsd/components.xsd" printOrder="Vertical">
<datasetRun subDataset="SurveyDataSet">
<dataSourceExpression><![CDATA[new net.sf.jasperreports.engine.data.JRBeanCollectionDataSource($F{surveyList})]]></dataSourceExpression>
</datasetRun>
<jr:listContents height="34" width="505">
<textField isStretchWithOverflow="true">
<reportElement style="report_value" x="125" y="17" width="265" height="15" positionType="Float" />
<textElement textAlignment="Left" />
<textFieldExpression><![CDATA[$F{question}]]></textFieldExpression>
</textField>
<textField isStretchWithOverflow="true">
<reportElement style="report_value_bold" x="300" y="17" width="195" height="15" isRemoveLineWhenBlank="true" positionType="Float" />
<textElement textAlignment="Right" />
<textFieldExpression><![CDATA[$F{response}]]></textFieldExpression>
</textField>
<line>
<reportElement style="line_light" x="105" y="33" width="400" height="1" positionType="FixRelativeToBottom" />
</line>
</jr:listContents>
</jr:list>
</componentElement>
</jr:listContents>
</jr:list>
</componentElement>
</band>
</detail>
Example output of what I'm seeing:
Expected: each Q/A appears right below the Q/A-line above it. There should not be any gaps between dates and the Q/A above it either.
I've tried tweaking various heights, postitionTypes, etc. to no avail. Feel like I'm probably missing something obvious but I've been staring at this too long. Appreciate any help!
Your innermost list reportElement is set to have a height of 0px while suddenly the listContents height is set to 34px but then only contains a TextElement of height 17px while the Detail band is set to 17px.
The basic concept when working with Lists in Jasperreports is that every inner list must have vertical space allocated in the list it is contained in. i.e. your innermost list must have space allocated in the outer list, positioned relative to other elements in the outer list. If a TextElement is streched due to isStretchWithOverflow="true" elements in the same List that are set to positionType="Float" will "Float" down and the list will extend. If the a inner list extends, the outer list will automatically also extend. (and elements in the outer list below the inner list will Float down if set to positionType="Float".
I've cleaned up your example:
<?xml version="1.0" encoding="UTF-8"?>
<!-- Created with Jaspersoft Studio version 6.20.0.final using JasperReports Library version 6.19.0 -->
<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="nbsp" pageWidth="595" pageHeight="842" columnWidth="555" leftMargin="20" rightMargin="20" topMargin="20" bottomMargin="20" uuid="77c97c1b-90ba-40a8-a5c3-f88b8a48a585">
<subDataset name="SurveyListDataSet" uuid="da0fc5b7-7621-4907-b2b7-e8fa130b1945">
<queryString>
<![CDATA[]]>
</queryString>
<field name="_THIS" class="java.lang.String"/>
</subDataset>
<subDataset name="SurveyDataSet" uuid="e7a6a451-fe26-427c-917d-59070a76a200">
<queryString>
<![CDATA[]]>
</queryString>
<field name="_THIS" class="java.lang.String"/>
</subDataset>
<detail>
<band height="34" splitType="Stretch">
<property name="com.jaspersoft.studio.unit.height" value="px"/>
<componentElement>
<reportElement x="0" y="0" width="505" height="34" uuid="0d598531-c684-4c2b-be01-9ced3fa81f81">
<property name="com.jaspersoft.studio.unit.height" value="px"/>
</reportElement>
<jr:list xmlns:jr="http://jasperreports.sourceforge.net/jasperreports/components" xsi:schemaLocation="http://jasperreports.sourceforge.net/jasperreports/components http://jasperreports.sourceforge.net/xsd/components.xsd" printOrder="Vertical">
<datasetRun subDataset="SurveyListDataSet" uuid="7eeeb416-bd57-43dc-bc19-47481921f2a7">
<dataSourceExpression><![CDATA[new net.sf.jasperreports.engine.data.JRBeanCollectionDataSource(java.util.Arrays.asList(new String[] { "2022-01-01", "2022-02-01", "2022-03-01", "2022-04-01" }))]]></dataSourceExpression>
</datasetRun>
<jr:listContents height="34" width="505">
<textField textAdjust="StretchHeight">
<reportElement x="110" y="0" width="265" height="15" uuid="c0bfd9da-139d-41a9-9b91-34c4db12ebe9"/>
<textElement textAlignment="Left"/>
<textFieldExpression><![CDATA[$F{_THIS}]]></textFieldExpression>
</textField>
<line>
<reportElement positionType="Float" x="105" y="16" width="400" height="1" uuid="d21b7ef6-f724-4ad9-a238-c68c28d486ab"/>
</line>
<componentElement>
<reportElement positionType="Float" x="0" y="17" width="505" height="17" uuid="54082666-799b-4117-92a5-255041315f7b">
<property name="com.jaspersoft.studio.unit.height" value="px"/>
<property name="com.jaspersoft.studio.unit.y" value="px"/>
</reportElement>
<jr:list printOrder="Vertical">
<datasetRun subDataset="SurveyDataSet" uuid="f955dac7-55df-4fc3-8e30-cdeefe73a5be">
<dataSourceExpression><![CDATA[new net.sf.jasperreports.engine.data.JRBeanCollectionDataSource(java.util.Arrays.asList(new String[] { "Question 1? ", "Question 2?", "Question 3?", "Question 4?" }))]]></dataSourceExpression>
</datasetRun>
<jr:listContents height="17" width="505">
<textField textAdjust="StretchHeight">
<reportElement x="125" y="0" width="265" height="15" uuid="c1fb3fef-53d7-4e64-b05a-0478aed19226">
<property name="com.jaspersoft.studio.unit.y" value="px"/>
</reportElement>
<textElement textAlignment="Left"/>
<textFieldExpression><![CDATA[$F{_THIS}]]></textFieldExpression>
</textField>
<textField textAdjust="StretchHeight">
<reportElement x="300" y="0" width="195" height="15" isRemoveLineWhenBlank="true" uuid="4dd5da20-e70f-4122-92e9-fea714edb33a">
<property name="com.jaspersoft.studio.unit.y" value="px"/>
</reportElement>
<textElement textAlignment="Right"/>
<textFieldExpression><![CDATA[$F{_THIS}]]></textFieldExpression>
</textField>
<line>
<reportElement positionType="Float" x="105" y="16" width="400" height="1" uuid="b2e07c02-8deb-49fb-9a68-9f431a9f363d">
<property name="com.jaspersoft.studio.unit.height" value="px"/>
<property name="com.jaspersoft.studio.unit.y" value="px"/>
</reportElement>
</line>
</jr:listContents>
</jr:list>
</componentElement>
</jr:listContents>
</jr:list>
</componentElement>
</band>
</detail>
</jasperReport>

How to reference one field to another in a subDataset?

If I have a Jasper report with two fields. For example:
<field name="counts" class="java.util.List"/>
<field name="names" class="java.util.List"/>
In the report is it possible to use the name field to "lookup" a value in the counts field if the counts field looks like this:
[{"Bob":10},{"Bill":5},{"John":2}]
So in the report I iterate over the names using a subDataSet:
<subDataset name="nameDetails" uuid="6f0e513d-9659-4dea-8c88-0fa9522d6aef">
<field name="name" class="java.lang.String">
<fieldDescription><![CDATA[name]]></fieldDescription>
</field>
</subDataset>
<componentElement>
<reportElement x="0" y="40" width="200" height="60"/>
<jr:list printOrder="Vertical">
<datasetRun subDataset="nameDetails">
<dataSourceExpression><![CDATA[new net.sf.jasperreports.engine.data.JRMapCollectionDataSource($F{names})]]></dataSourceExpression>
</datasetRun>
<jr:listContents height="60" width="200">
<textField>
<reportElement x="0" y="0" width="200" height="20"/>
<textFieldExpression><![CDATA["Name: " + $F{name}]]></textFieldExpression>
</textField>
...
This prints out the name of each person in the names field, but additionally I want to use the "name" of each person to look-up the count for the person in the counts field, but not sure if I can do this or how?
Yes you can reference fields, in your case however you need first to pass also the other field to the subdataset, hence you can only reference data that is present in the actual subdataset.
One way is to pass the field counts as a parameter.
<datasetParameter name="counts">
<datasetParameterExpression><![CDATA[$F{counts}]]></datasetParameterExpression>
</datasetParameter>
For example assuming the List have data in same position.
List<String> names = Arrays.asList(new String[] { "Bob", "Bill", "John" });
List<Integer> counts = Arrays.asList(new Integer[] { 10, 5, 2 });
You could use the built in parameter $V{REPORT_COUNT} to retrive data from the other List, $P{counts}.get(($V{REPORT_COUNT}.intValue()-1))
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="firstReport" pageWidth="595" pageHeight="842" whenNoDataType="BlankPage" columnWidth="555" leftMargin="20" rightMargin="20" topMargin="20" bottomMargin="20" uuid="597c0716-df6b-42ec-a7c8-863eb1b7174a">
<subDataset name="nameDetails" uuid="63078d78-2076-4a72-8728-ee6ca3ded99f">
<parameter name="counts" class="java.util.List"/>
<field name="_THIS" class="java.lang.String"/>
</subDataset>
<field name="counts" class="java.util.List"/>
<field name="names" class="java.util.List"/>
<detail>
<band height="50">
<componentElement>
<reportElement x="0" y="0" width="550" height="30" uuid="180fb785-64b3-4f04-81f6-7076444d871d"/>
<jr:list xmlns:jr="http://jasperreports.sourceforge.net/jasperreports/components" xsi:schemaLocation="http://jasperreports.sourceforge.net/jasperreports/components http://jasperreports.sourceforge.net/xsd/components.xsd" printOrder="Vertical">
<datasetRun subDataset="nameDetails" uuid="8d40297b-e33b-4681-9533-d6f1ab63c6f2">
<datasetParameter name="counts">
<datasetParameterExpression><![CDATA[$F{counts}]]></datasetParameterExpression>
</datasetParameter>
<dataSourceExpression><![CDATA[new net.sf.jasperreports.engine.data.JRBeanCollectionDataSource($F{names})]]></dataSourceExpression>
</datasetRun>
<jr:listContents height="30" width="550">
<textField>
<reportElement x="0" y="0" width="550" height="30" uuid="48e09c52-3b6a-40cf-b572-2abccfcd83cc"/>
<textElement verticalAlignment="Middle">
<font size="14"/>
</textElement>
<textFieldExpression><![CDATA[$F{_THIS} + ":" + $P{counts}.get(($V{REPORT_COUNT}.intValue()-1))]]></textFieldExpression>
</textField>
</jr:listContents>
</jr:list>
</componentElement>
</band>
</detail>
</jasperReport>
Result
Note: If you have control on data arriving, however I would strongly suggest you pass the data in a single object (List), since this type of referencing is error prone, in this case if the size of the Lists are different, the report generation will fail

How to repeat textfield by parameter in jaspersoft?

I have a text for a document, that can repeat itself for more than 100 times, what I was trying to do is putting a lot of textfield's and then putting a print when expression so that only the quantity of the parameters that I gave would repeat.
The problem is that it can repeat more times than I thought. I like to pass as parameter the number of times it should repeat, not using datasource.
An easy way to repeat text would be to actually use a datasource, the JREmptyDataSource in constructor you can define how many records you like.
I will show an example using the jr:list component to repeat text, but you could use the jr:table component or a subreport instead.
Pass to this component an empty datasource with the number of records you like (hence the parameter defined):
<dataSourceExpression><![CDATA[new net.sf.jasperreports.engine.JREmptyDataSource($P{NR_REPEAT})]]></dataSourceExpression>
Full 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="Blank_A4" pageWidth="595" pageHeight="842" columnWidth="555" leftMargin="20" rightMargin="20" topMargin="20" bottomMargin="20" uuid="716e18ba-d975-40fa-9be2-89f43a4ab69c">
<property name="com.jaspersoft.studio.data.defaultdataadapter" value="One Empty Record"/>
<subDataset name="RepeatDataset" uuid="185d5db2-6f6b-4c9a-9905-e7a554b6a8fa">
<queryString>
<![CDATA[]]>
</queryString>
</subDataset>
<parameter name="NR_REPEAT" class="java.lang.Integer">
<defaultValueExpression><![CDATA[5]]></defaultValueExpression>
</parameter>
<queryString>
<![CDATA[]]>
</queryString>
<title>
<band height="22">
<textField>
<reportElement x="0" y="0" width="260" height="20" uuid="b0a2bf35-f015-4b85-aa87-b5587e48de10"/>
<textElement verticalAlignment="Middle"/>
<textFieldExpression><![CDATA["NR. REPEAT IS: " + $P{NR_REPEAT}]]></textFieldExpression>
</textField>
</band>
</title>
<detail>
<band height="31" splitType="Stretch">
<componentElement>
<reportElement x="0" y="0" width="550" height="22" uuid="0d5f8ed2-c697-4337-b0b0-2411da8cc5fa">
<property name="com.jaspersoft.studio.unit.height" value="px"/>
</reportElement>
<jr:list xmlns:jr="http://jasperreports.sourceforge.net/jasperreports/components" xsi:schemaLocation="http://jasperreports.sourceforge.net/jasperreports/components http://jasperreports.sourceforge.net/xsd/components.xsd" printOrder="Vertical">
<datasetRun subDataset="RepeatDataset" uuid="e98a25f7-2d4e-403e-8199-0d3573bb3a3e">
<dataSourceExpression><![CDATA[new net.sf.jasperreports.engine.JREmptyDataSource($P{NR_REPEAT})]]></dataSourceExpression>
</datasetRun>
<jr:listContents height="22" width="550">
<textField>
<reportElement x="0" y="0" width="550" height="22" uuid="21984a90-5517-4c8b-82f0-1fe682728830">
<property name="com.jaspersoft.studio.unit.height" value="px"/>
</reportElement>
<textElement verticalAlignment="Middle"/>
<textFieldExpression><![CDATA[$V{REPORT_COUNT} + " - Hello world"]]></textFieldExpression>
</textField>
</jr:listContents>
</jr:list>
</componentElement>
</band>
</detail>
</jasperReport>
Output setting NR_REPEAT to 5

How to add Ad Hoc database content to Textfield

I have an input parameter which is an ID.
I want to use a lookup table in the database to expand that ID into a long name for use in the report title.
How could I just add text into a textfield from a SQL query without needing to worry about rows of tabular data?
You can use the List component in the Title band. This List (or Table component) will be associated with another additional (non main) datasource for showing information (the Name by Id passed via Parameter in your case).
The main datasource will be used by Detail band (or another Table component with the its own datasource) for showing data filtered by parameter's value (Id in your case).
With help of textField's property isStretchWithOverflow (with true value) we can garantee that all text will be drawing with the textField.
The sample
In this sample I've used the DB distributed with the Jaspersoft Studio. The parameter addrId was used for filtering data by the id field of address table. This parameter was mapped to the List's datasource parameter with the same name (addrId). Yes, I've used the List component placed on Title band for showing information about the value of our external parameter (the city and the street of address in this sample). At the Detail band we are showing the information about documents (table document) related to our address (defined by addrId)
The report's template
<?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="growing_text" pageWidth="595" pageHeight="842" columnWidth="555" leftMargin="20" rightMargin="20" topMargin="20" bottomMargin="20" uuid="77f0cb04-7f4b-43dc-af12-89c25fa7c58c">
<subDataset name="dsAddrTitle" uuid="0eb7cd0c-f4f1-408d-be13-dc484fda80d5">
<property name="com.jaspersoft.studio.data.defaultdataadapter" value="Sample DB"/>
<parameter name="addrId" class="java.lang.Integer"/>
<queryString>
<![CDATA[SELECT city + ', ' + street AS name FROM address WHERE id=$P{addrId}]]>
</queryString>
<field name="NAME" class="java.lang.String"/>
</subDataset>
<parameter name="addrId" class="java.lang.Integer">
<defaultValueExpression><![CDATA[33]]></defaultValueExpression>
</parameter>
<queryString>
<![CDATA[SELECT ID, ADDRESSID, TOTAL FROM DOCUMENT WHERE ADDRESSID=$P{addrId} ORDER BY ADDRESSID]]>
</queryString>
<field name="ID" class="java.lang.Integer"/>
<field name="ADDRESSID" class="java.lang.Integer"/>
<field name="TOTAL" class="java.math.BigDecimal"/>
<title>
<band height="10" splitType="Stretch">
<componentElement>
<reportElement x="160" y="0" width="40" height="10" uuid="f4cb4e5c-e2d7-4927-b143-4cfcd7d99b76"/>
<jr:list xmlns:jr="http://jasperreports.sourceforge.net/jasperreports/components" xsi:schemaLocation="http://jasperreports.sourceforge.net/jasperreports/components http://jasperreports.sourceforge.net/xsd/components.xsd" ignoreWidth="true">
<datasetRun subDataset="dsAddrTitle" uuid="4bf3eb57-f752-4856-ac3a-fd7e3a33f434">
<parametersMapExpression><![CDATA[$P{REPORT_PARAMETERS_MAP}]]></parametersMapExpression>
<datasetParameter name="addrId">
<datasetParameterExpression><![CDATA[$P{addrId}]]></datasetParameterExpression>
</datasetParameter>
<connectionExpression><![CDATA[$P{REPORT_CONNECTION}]]></connectionExpression>
</datasetRun>
<jr:listContents height="30" width="100">
<textField isStretchWithOverflow="true">
<reportElement x="0" y="0" width="40" height="10" uuid="1b533c30-7868-450b-a5b9-59d5130dcb67"/>
<textFieldExpression><![CDATA[$F{NAME}]]></textFieldExpression>
</textField>
</jr:listContents>
</jr:list>
</componentElement>
</band>
</title>
<columnHeader>
<band height="30">
<staticText>
<reportElement x="0" y="0" width="185" height="30" uuid="100faa3b-790d-4dc6-b86c-8911a8762207"/>
<text><![CDATA[ID]]></text>
</staticText>
<staticText>
<reportElement x="185" y="0" width="185" height="30" uuid="aef6af65-f7b5-42e9-a102-aeb272f99103"/>
<text><![CDATA[ADDRESSID]]></text>
</staticText>
<staticText>
<reportElement x="370" y="0" width="185" height="30" uuid="2c176a21-6387-4505-836e-7e250751755f"/>
<text><![CDATA[TOTAL]]></text>
</staticText>
</band>
</columnHeader>
<detail>
<band height="30" splitType="Stretch">
<textField>
<reportElement x="0" y="0" width="185" height="30" uuid="22cbe96d-5322-40e3-bd96-d2aa9bf35dd2"/>
<textFieldExpression><![CDATA[$F{ID}]]></textFieldExpression>
</textField>
<textField>
<reportElement x="185" y="0" width="185" height="30" uuid="3adedcc9-f60e-4664-bbe8-6b7d7b8e13a4"/>
<textFieldExpression><![CDATA[$F{ADDRESSID}]]></textFieldExpression>
</textField>
<textField pattern="#,##0.00#">
<reportElement x="370" y="0" width="185" height="30" uuid="48041fd6-1375-4819-8ebb-ffd4aef84889"/>
<textFieldExpression><![CDATA[$F{TOTAL}]]></textFieldExpression>
</textField>
</band>
</detail>
</jasperReport>
The output result

Jasper Report graph in iReport repeating

I have a line graph in iReport which is incrementally repeating in every page, that is, if the graph has 30 x/y pairs (this is dynamic), the report will have 30 pages, of which the first will have just one value, the 2nd two values, and so on. Only the last one will contain the complete graph.
Questions "chart repeat many time" and "Problem with charting using JasperReport" and "How to print the grand total only in the last page of a very long report?" did not solve my problem. I understand that putting the chart in the Detail section makes the chart repeat, but putting it in the Summary, Footer, lastPageFooter, Title, etc. sections makes it display only one value. Same when I put it in the Detail section and use <printWhenExpression>.
My code:
<?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="nodes-allarmipersistenti" language="groovy" pageWidth="842" pageHeight="595" orientation="Landscape" columnWidth="802" 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="0"/>
<field name="day" class="java.lang.Number"/>
<field name="month" class="java.lang.String"/>
<field name="year" class="java.lang.String"/>
<field name="dsunita" class="java.lang.String"/>
<field name="valueNumber" class="java.lang.Number"/>
<field name="logo" class="java.lang.String"/>
<field name="today" class="java.lang.String"/>
<field name="option" class="java.lang.String"/>
<title>
<band height="89">
<staticText>
<reportElement mode="Opaque" x="0" y="67" width="424" height="22" backcolor="#CCFFFF"/>
<textElement textAlignment="Right" verticalAlignment="Middle" markup="none">
<font size="10" isBold="true" pdfFontName="Helvetica-Bold" isPdfEmbedded="true"/>
</textElement>
<text><![CDATA[GRAFICO PARAMETRO]]></text>
</staticText>
<staticText>
<reportElement x="600" y="0" width="100" height="38"/>
<textElement verticalAlignment="Middle"/>
<text><![CDATA[Stampato in data]]></text>
</staticText>
<textField>
<reportElement x="700" y="0" width="102" height="38"/>
<textElement textAlignment="Right" verticalAlignment="Middle"/>
<textFieldExpression><![CDATA[$F{today}]]></textFieldExpression>
</textField>
<image>
<reportElement x="0" y="0" width="100" height="67"/>
<imageExpression><![CDATA[$F{logo}]]></imageExpression>
</image>
<staticText>
<reportElement x="700" y="38" width="102" height="29"/>
<textElement textAlignment="Right"/>
<text><![CDATA[MaRe - Telecontrollo]]></text>
</staticText>
<textField>
<reportElement mode="Opaque" x="424" y="67" width="378" height="22" backcolor="#CCFFFF"/>
<textElement verticalAlignment="Middle"/>
<textFieldExpression><![CDATA[' ' + $F{option}]]></textFieldExpression>
</textField>
</band>
</title>
<lastPageFooter>
<band height="387" splitType="Stretch">
<xyLineChart>
<chart evaluationTime="Page">
<reportElement x="0" y="0" width="802" height="387"/>
<chartTitle/>
<chartSubtitle/>
<chartLegend/>
</chart>
<xyDataset>
<dataset incrementType="Report"/>
<xySeries>
<seriesExpression><![CDATA["Unità " + $F{dsunita}]]></seriesExpression>
<xValueExpression><![CDATA[$F{day}]]></xValueExpression>
<yValueExpression><![CDATA[$F{valueNumber}]]></yValueExpression>
</xySeries>
</xyDataset>
<linePlot>
<plot/>
</linePlot>
</xyLineChart>
</band>
</lastPageFooter>
</jasperReport>
Datasource here is a JRBeanCollectionDataSource.
Putting it in the Detail band is wrong (as you noticed). Putting it in the Title or Summary will work. Your choice of evaluationTime="Page" doesn't look right. Try changing this to evaluationTime="Report"