How to reference one field to another in a subDataset? - jasper-reports

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

Related

Jasper Json nested lists

I'm new in Jasper reports, so I'll write my whole task, if it's allowed..
I'm trying to parse json data to print in it PDF. Data is coming from oracle DB, written in CLOB column, so I have list of json-clob records.
I have nested lists json (and clob) data, so I can't build 3 stair nested report with my jasper experience. I have json structure like this:
{
title: 'Main Title',
blocks: [{
title: 'Inner Title',
items: [{
key: '1',
value: 'some text'
}, {
key: '2',
value: 'some other text'
}]
}, {
text: 'here may be other fields (text, not title)'
}]
}
For this json data, I want to get this result in PDF (just simple output):
Main Title
Inner Title
1 some text
2 some other text
here may be other fields (text, not title)
Firstly, I use CLOB converting in json source ( script:
< dataSourceExpression >
< ![CDATA[new net.sf.jasperreports.engine.data.JsonQLDataSource(new ByteArrayInputStream($F{JSON_CLOB_RECORD}.getBytes("UTF-8")))]] >
< /dataSourceExpression >
source: nested jasper subreports with json datasource ).
After that, I use jr:list and textfield to print main titles. And I'm done, don't know how to continue.
I searched nested lists (jr:list) but nothing, can't fit to my task.
P.S. I have subDataset for parsing data from CLOB to json with fields title (java.lang.String) and blocks (I tried here java.util.Collection and ArrayList but errors occurred, than I wrote java.lang.Object. Is it necessary to write blocks field in this subDataset?). I also added subDataset for blocks list, is it needed? And if yes, so I have to add items subDataset too, right? Also, I tried to add subReport after main title textfield, for blocks list and added dataSourceExpression but can't continue.
Need some help.
I would suggest using a subreport, instead of a list or nested lists, because you gain more flexibility in this case.
In the main report you should discard the list element and the dataset and use a subreport, something like:
<subreport>
<reportElement x="0" y="0" width="550" height="50" uuid="37861aca-d444-4aec-ad03-baa310540327"/>
<subreportParameter name="JSON_INPUT_STREAM">
<subreportParameterExpression><![CDATA[new ByteArrayInputStream($F{JSON_CLOB_RECORD}.getBytes("UTF-8"))]]></subreportParameterExpression>
</subreportParameter>
<subreportExpression><![CDATA["Subreport.jasper"]]></subreportExpression>
</subreport>
Here we only need the JSON_INPUT_STREAM so that the subreport will construct a dataSource based on the query and its language.
Case 1. If you are mostly interested in the items key, then the subreport(Subreport.jrxml) could be pretty basic like so:
<?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="Subreport" pageWidth="595" pageHeight="842" columnWidth="555" leftMargin="20" rightMargin="20" topMargin="20" bottomMargin="20" uuid="a3dd10f8-b28c-4c11-b582-9b169e8aa417">
<queryString language="jsonql">
<![CDATA[..items.*]]>
</queryString>
<field name="mainTitle" class="java.lang.String">
<property name="net.sf.jasperreports.jsonql.field.expression" value="$.title"/>
</field>
<field name="key" class="java.lang.String">
<property name="net.sf.jasperreports.jsonql.field.expression" value="key"/>
</field>
<field name="value" class="java.lang.String">
<property name="net.sf.jasperreports.jsonql.field.expression" value="value"/>
</field>
<field name="blockTitle" class="java.lang.String">
<property name="net.sf.jasperreports.jsonql.field.expression" value="^^.title"/>
</field>
<background>
<band splitType="Stretch"/>
</background>
<detail>
<band height="90" splitType="Stretch">
<textField>
<reportElement isPrintRepeatedValues="false" x="0" y="30" width="100" height="30" isRemoveLineWhenBlank="true" uuid="172de051-3d2c-4458-b01e-ab06e4e1bb3b"/>
<textFieldExpression><![CDATA[$F{blockTitle}]]></textFieldExpression>
</textField>
<textField>
<reportElement isPrintRepeatedValues="false" x="0" y="0" width="100" height="30" isRemoveLineWhenBlank="true" uuid="94f57756-a5a8-402f-ad23-7cdbe2a00e59"/>
<textFieldExpression><![CDATA[$F{mainTitle}]]></textFieldExpression>
</textField>
<textField>
<reportElement x="0" y="60" width="100" height="30" uuid="7dbbdfd8-5a0e-4288-ae39-21f13cd4d921"/>
<textFieldExpression><![CDATA[$F{key} + " " + $F{value}]]></textFieldExpression>
</textField>
</band>
</detail>
</jasperReport>
Notice the isPrintRepeatedValues="false" and the isRemoveLineWhenBlank="true" properties that remove the duplicates and the lines so that you get the desired output.
I've simulated your case with a serialized JSON and got the following:
Case 2. If you are interested in all the blocks object data you would have to land on the blocks item in your query and create a list/subreport for the items key, something like:
<?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="Report" pageWidth="595" pageHeight="842" columnWidth="555" leftMargin="20" rightMargin="20" topMargin="20" bottomMargin="20" uuid="a3dd10f8-b28c-4c11-b582-9b169e8aa417">
<subDataset name="BlockItemsDataset" uuid="83c1b8ed-e880-4474-a809-39d95277341f">
<field name="key" class="java.lang.String">
<property name="net.sf.jasperreports.jsonql.field.expression" value="key"/>
</field>
<field name="value" class="java.lang.String">
<property name="net.sf.jasperreports.jsonql.field.expression" value="value"/>
</field>
</subDataset>
<queryString language="jsonql">
<![CDATA[blocks]]>
</queryString>
<field name="mainTitle" class="java.lang.String">
<property name="net.sf.jasperreports.jsonql.field.expression" value="$.title"/>
</field>
<field name="blockTitle" class="java.lang.String">
<property name="net.sf.jasperreports.jsonql.field.expression" value="title"/>
</field>
<background>
<band splitType="Stretch"/>
</background>
<detail>
<band height="91" splitType="Stretch">
<textField>
<reportElement isPrintRepeatedValues="false" x="0" y="0" width="100" height="30" isRemoveLineWhenBlank="true" uuid="94f57756-a5a8-402f-ad23-7cdbe2a00e59"/>
<textFieldExpression><![CDATA[$F{mainTitle}]]></textFieldExpression>
</textField>
<textField>
<reportElement isPrintRepeatedValues="false" x="0" y="30" width="100" height="30" isRemoveLineWhenBlank="true" uuid="172de051-3d2c-4458-b01e-ab06e4e1bb3b"/>
<textFieldExpression><![CDATA[$F{blockTitle}]]></textFieldExpression>
</textField>
<componentElement>
<reportElement x="0" y="61" width="200" height="30" uuid="7a94d84d-d58e-4508-b143-3704fa7f5cd3"/>
<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="BlockItemsDataset" uuid="a866f955-7594-4fb9-9bb2-936282963dea">
<dataSourceExpression><![CDATA[((net.sf.jasperreports.engine.data.JsonQLDataSource)$P{REPORT_DATA_SOURCE}).subDataSource("items")]]></dataSourceExpression>
</datasetRun>
<jr:listContents height="30" width="200">
<textField>
<reportElement x="0" y="0" width="200" height="30" uuid="36a771fa-f949-4c69-a62c-1df0c610a2d3"/>
<textFieldExpression><![CDATA[$F{key} + " " + $F{value}]]></textFieldExpression>
</textField>
</jr:listContents>
</jr:list>
</componentElement>
</band>
</detail>
</jasperReport>

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 use the same REPORT_COUNT in multiple tables incrementing it?

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)

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 reports: positioning element on bottom of the page

I wonder if it's possible to position dynamically growing (table) element to the bottom of the page? My table element is on detail band, just above the page footer band.
Basically in my case the position of the topmost row of the table would be dynamically changing all the time based on the amount of rows in the table. But I'm not sure if creating this kind of presentation is even possible with Jasper where the table would be basically "growing" from bottom to top where the last row of the table would be basically fixed to the bottom of the page, just above page footer. There would be no problem if the position of the table's topmost row would be always fixed and table would "grow normally" from the fixed top position towards the bottom of the page...
I tried setting the table's position type property to Fix relative to bottom, but after that the whole table disappeared completely. This was the only thing I was able to think of so far to solve my issue.
Maybe the easiest way to achieve this is to put your table in a <groupFooter> with footerPosition="StackAtBottom"
The correct way to group depends on your datasource, but let assume you have just one table creating a dummy group.
Example of dummy group with table StackAtBottom of page
<?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="Example2" pageWidth="595" pageHeight="842" columnWidth="555" leftMargin="20" rightMargin="20" topMargin="20" bottomMargin="20" uuid="ca579c38-1e4f-4993-a020-efcea9d1096e">
<style name="table"><box><pen lineWidth="1.0" lineColor="#000000"/></box></style>
<style name="table_TD" mode="Opaque" backcolor="#FFFFFF"><box><pen lineWidth="0.5" lineColor="#000000"/></box></style>
<subDataset name="Table" uuid="982be61b-ae46-4404-a9a0-30ba13e8c414">
<queryString language="xPath">
<![CDATA[/report/table/entry]]>
</queryString>
<field name="name" class="java.lang.String">
<fieldDescription><![CDATA[name]]></fieldDescription>
</field>
<field name="class" class="java.lang.String">
<fieldDescription><![CDATA[class]]></fieldDescription>
</field>
</subDataset>
<queryString language="xPath">
<![CDATA[/report]]>
</queryString>
<group name="dummy" footerPosition="StackAtBottom">
<groupFooter>
<band height="29">
<componentElement>
<reportElement key="table" style="table" x="0" y="0" width="360" height="20" uuid="53ea5a0e-1218-4150-ab5a-5f947e73b284"/>
<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="Table" uuid="64092841-9993-4ccd-89b4-84a546c719cf">
<dataSourceExpression><![CDATA[((net.sf.jasperreports.engine.data.JRXmlDataSource)$P{REPORT_DATA_SOURCE}).subDataSource("report/table/entry")]]></dataSourceExpression>
</datasetRun>
<jr:column width="90" uuid="4f5b1813-a9cc-4f83-9bdb-b0d8c4299133">
<jr:detailCell style="table_TD" height="20">
<textField>
<reportElement x="0" y="0" width="90" height="20" uuid="f1a97e19-e23d-40b6-ad95-10614f516db7"/>
<textFieldExpression><![CDATA[$F{class}]]></textFieldExpression>
</textField>
</jr:detailCell>
</jr:column>
<jr:column width="90" uuid="98cfbe63-f865-419c-ad8f-d8af2ed706ba">
<jr:detailCell style="table_TD" height="20">
<textField>
<reportElement x="0" y="0" width="90" height="20" uuid="0480f047-02ba-4ec4-b12a-ef56a3cbfee9"/>
<textFieldExpression><![CDATA[$F{name}]]></textFieldExpression>
</textField>
</jr:detailCell>
</jr:column>
</jr:table>
</componentElement>
</band>
</groupFooter>
</group>
<detail>
<band height="17" splitType="Stretch"/>
</detail>
</jasperReport>
Result