Using JasperReports Version 6.20.
I have two textfields that are elements in a list that I want to iterate on. One textfield should be placed under the other. But when I try to do it, they overlap each other in the report. I can't use the simple y
value, because I actually want a sublist in between that grows dynamically. For simplicity sake I only show the two textfields in the xml code.
Here is the example:
<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="TableGroup" uuid="28256056-95ed-4ce9-80ee-47a10ede48f1">
<datasetParameter name="myObject">
<datasetParameterExpression><![CDATA[$P{myObject}]]></datasetParameterExpression>
</datasetParameter>
<dataSourceExpression><![CDATA[new net.sf.jasperreports.engine.data.JRBeanCollectionDataSource($P{myObject}.getMyList())]]></dataSourceExpression>
</datasetRun>
<jr:listContents height="250" width="500">
<frame>
<reportElement x="0" y="0" width="500" height="250" uuid="566f22c8-abbe-4709-962c-c393366555bf"/>
<textField textAdjust="StretchHeight">
<reportElement positionType="Float" stretchType="ContainerHeight" x="0" y="0" width="200" height="20" uuid="e8873bea-aa28-4439-b4cf-3fd40b487ae6"/>
<textFieldExpression><![CDATA[$F{elementOne}]]></textFieldExpression>
</textField>
<textField textAdjust="StretchHeight">
<reportElement positionType="Float" stretchType="ContainerHeight" x="0" y="0" width="310" height="20" uuid="fb38a2e3-f141-472b-9fe0-fd1b998eb611"/>
<textFieldExpression><![CDATA[$F{elementTwo}]]></textFieldExpression>
</textField>
</frame>
</jr:listContents>
</jr:list>
The printOrder
is "Vertical". I've tried multiple attributes for example positionType="Float"
such that it is dynamically loaded but it just doesn't work. I tried to put it in a subreport and in bands but then the sublist is the problem because the subreport iterates for each element once in the sublist and not once for all elements (Hence there are too many elements displayed).
How can I place the elements in the list vertically on top of each other dynamically?
The key to align items in a list vertically to use bands. Since the bands are not placeable in a jr:list I needed to create a subreport. Putting the block in listContents in a subReport resolves the problem.