Making text fields stretch in two separate subreports - jasper-reports

I have a main subreport, that contains two similar subreports placed next to each other.
These two similar subreports both contain a text field in the detail band. Detail band is set to stretch.
My problem is when one of the text fields contain a long text, and the other is not,there will be a "gap" on side with the short text. The text field with the short text should stretch also.
Is there a way to achive this while maintaining two separate subreports? Or do I have create one subreport from the two, putting both text fields into one subreport?
Here's a simplifeid version of the main subreport, and the two subreport containing the text fields.
Main report:
<?xml version="1.0" encoding="UTF-8"?>
<!-- Created with Jaspersoft Studio version 6.6.0.final using JasperReports Library version 6.6.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="Invoice" pageWidth="595" pageHeight="255" columnWidth="595" leftMargin="0" rightMargin="0" topMargin="0" bottomMargin="0" resourceBundle="InvoiceBundle" uuid="4328d8a4-e5d5-4d7d-9fba-b42407325799">
<property name="ireport.zoom" value="1.5000000000000007"/>
<property name="ireport.x" value="0"/>
<property name="ireport.y" value="0"/>
<property name="com.jaspersoft.studio.data.defaultdataadapter" value="develop trunk"/>
<property name="com.jaspersoft.studio.data.sql.tables" value=""/>
<style name="table">
<box>
<pen lineWidth="1.0" lineColor="#000000"/>
</box>
</style>
<parameter name="ID" class="java.lang.Long">
<defaultValueExpression><![CDATA[]]></defaultValueExpression>
</parameter>
<parameter name="SUBREPORT_DIR" class="java.lang.String">
<defaultValueExpression><![CDATA["./"]]></defaultValueExpression>
</parameter>
<parameter name="DATEFORMAT" class="java.lang.String"/>
<queryString>
<![CDATA[SELECT 1 -- This is a must, because subreports in Detail Band will only show data if the query has result. TODO: Move this supreport into Header Band.]]>
</queryString>
<detail>
<band height="240" splitType="Stretch">
<frame>
<reportElement style="table" positionType="Float" x="0" y="140" width="555" height="80" uuid="ee798e27-e04b-46e1-ae6b-b85f881d6878"/>
<box>
<topPen lineWidth="1.0" lineStyle="Solid" lineColor="#000000"/>
<leftPen lineWidth="1.0" lineStyle="Solid" lineColor="#000000"/>
<bottomPen lineWidth="1.0" lineStyle="Solid" lineColor="#000000"/>
<rightPen lineWidth="1.0" lineStyle="Solid" lineColor="#000000"/>
</box>
<subreport isUsingCache="false">
<reportElement style="table" positionType="Float" stretchType="RelativeToTallestObject" x="0" y="0" width="300" height="80" uuid="2b946dfa-c599-4ea2-873b-d68073885475"/>
<subreportParameter name="SUBREPORT_DIR">
<subreportParameterExpression><![CDATA[$P{SUBREPORT_DIR}]]></subreportParameterExpression>
</subreportParameter>
<subreportParameter name="REPORT_RESOURCE_BUNDLE">
<subreportParameterExpression><![CDATA[$P{REPORT_RESOURCE_BUNDLE}]]></subreportParameterExpression>
</subreportParameter>
<connectionExpression><![CDATA[$P{REPORT_CONNECTION}]]></connectionExpression>
<subreportExpression><![CDATA[$P{SUBREPORT_DIR} + "Left.jasper"]]></subreportExpression>
</subreport>
<subreport isUsingCache="false">
<reportElement style="table" positionType="Float" stretchType="RelativeToTallestObject" x="300" y="0" width="255" height="80" uuid="aa26fd8b-b945-4d61-b3c6-2019f1e2c779"/>
<subreportParameter name="SUBREPORT_DIR">
<subreportParameterExpression><![CDATA[$P{SUBREPORT_DIR}]]></subreportParameterExpression>
</subreportParameter>
<subreportParameter name="REPORT_RESOURCE_BUNDLE">
<subreportParameterExpression><![CDATA[$P{REPORT_RESOURCE_BUNDLE}]]></subreportParameterExpression>
</subreportParameter>
<connectionExpression><![CDATA[$P{REPORT_CONNECTION}]]></connectionExpression>
<subreportExpression><![CDATA[$P{SUBREPORT_DIR} + "Right.jasper"]]></subreportExpression>
</subreport>
</frame>
</band>
</detail>
</jasperReport>
Subreport on the left side, called Left.jasper:
<?xml version="1.0" encoding="UTF-8"?>
<!-- Created with Jaspersoft Studio version 6.6.0.final using JasperReports Library version 6.6.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="Invoice" pageWidth="300" pageHeight="255" columnWidth="300" leftMargin="0" rightMargin="0" topMargin="0" bottomMargin="0" resourceBundle="InvoiceBundle" uuid="4328d8a4-e5d5-4d7d-9fba-b42407325799">
<property name="ireport.zoom" value="1.5000000000000007"/>
<property name="ireport.x" value="0"/>
<property name="ireport.y" value="0"/>
<property name="com.jaspersoft.studio.data.defaultdataadapter" value="develop trunk"/>
<property name="com.jaspersoft.studio.data.sql.tables" value=""/>
<style name="table">
<box>
<pen lineWidth="1.0" lineColor="#000000"/>
</box>
</style>
<parameter name="SUBREPORT_DIR" class="java.lang.String">
<defaultValueExpression><![CDATA[]]></defaultValueExpression>
</parameter>
<parameter name="DATEFORMAT" class="java.lang.String"/>
<queryString>
<![CDATA[SELECT 'this is a short text' AS short_text]]>
</queryString>
<field name="short_text" class="java.lang.String"/>
<detail>
<band height="80" splitType="Stretch">
<frame>
<reportElement style="table" positionType="Float" stretchType="RelativeToTallestObject" x="0" y="0" width="300" height="80" uuid="7688bc26-63fe-4013-b7dc-514f2f078be1"/>
<textField isStretchWithOverflow="true" isBlankWhenNull="true">
<reportElement positionType="Float" stretchType="RelativeToTallestObject" x="5" y="20" width="245" height="15" isPrintWhenDetailOverflows="true" uuid="c71b1e9d-f637-4511-b304-ba5a9603331e"/>
<textElement>
<font fontName="DejaVu Sans" size="9"/>
</textElement>
<textFieldExpression><![CDATA[$F{short_text}]]></textFieldExpression>
</textField>
</frame>
</band>
</detail>
</jasperReport>
Subreport on the right side, called Right.jasper:
<?xml version="1.0" encoding="UTF-8"?>
<!-- Created with Jaspersoft Studio version 6.6.0.final using JasperReports Library version 6.6.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="Invoice" pageWidth="255" pageHeight="255" columnWidth="255" leftMargin="0" rightMargin="0" topMargin="0" bottomMargin="0" resourceBundle="InvoiceBundle" uuid="4328d8a4-e5d5-4d7d-9fba-b42407325799">
<property name="ireport.zoom" value="1.5000000000000007"/>
<property name="ireport.x" value="0"/>
<property name="ireport.y" value="0"/>
<property name="com.jaspersoft.studio.data.defaultdataadapter" value="develop trunk"/>
<property name="com.jaspersoft.studio.data.sql.tables" value=""/>
<style name="table">
<box>
<pen lineWidth="1.0" lineColor="#000000"/>
</box>
</style>
<parameter name="SUBREPORT_DIR" class="java.lang.String">
<defaultValueExpression><![CDATA[]]></defaultValueExpression>
</parameter>
<queryString>
<![CDATA[select 'This is a very long text, that makes the text field stretch.
This is a very long text, that makes the text field stretch.
This is a very long text, that makes the text field stretch.
This is a very long text, that makes the text field stretch.
This is a very long text, that makes the text field stretch.
This is a very long text, that makes the text field stretch.
This is a very long text, that makes the text field stretch.
This is a very long text, that makes the text field stretch.
This is a very long text, that makes the text field stretch.
' AS long_text]]>
</queryString>
<field name="long_text" class="java.lang.String"/>
<detail>
<band height="80" splitType="Stretch">
<frame>
<reportElement style="table" positionType="Float" stretchType="RelativeToTallestObject" x="0" y="0" width="255" height="80" uuid="9402fe9b-072f-4d99-9686-eaf896fa5281"/>
<textField isStretchWithOverflow="true" isBlankWhenNull="true">
<reportElement positionType="Float" stretchType="RelativeToTallestObject" x="5" y="20" width="250" height="15" isPrintWhenDetailOverflows="true" uuid="cf207ce1-909e-4e80-802b-7b8dcb22f05b"/>
<textElement>
<font fontName="DejaVu Sans" size="9"/>
</textElement>
<textFieldExpression><![CDATA[$F{long_text}]]></textFieldExpression>
</textField>
</frame>
</band>
</detail>
</jasperReport>

Related

How to create a table with both static and dynamic values from parameters?

I want to create a table with static and dynamic values like the following picture:
As you can see, the red values are dynamic (values in parameters) while the rest of the table is static.
The problem is that I cannot add more than one detail row to the table.
Even if I use normal Text Field and Static Text elements instead of a Table I wouldn't be able to stretch the values (in case a value needs more than a single line) without overlapping.
How can I achieve this?
To use the jr:table component you need to have a datasource, normally you should get the data from some backend code, passing it to the report for example as a List in a parameter. Hence instead of passing the single parameters, you pass a datasource with both name and values.
However, for fun? we can create a datasource also within the jrxml code for example in your case I would use a ListOfArrayDataSource(java.util.List<java.lang.Object[]> records, java.lang.String[] columnNames)
The code to create the first two entries would be something this.
new net.sf.jasperreports.engine.data.ListOfArrayDataSource(
Arrays.asList(
new String[]{"Name", $P{name}},
new String[]{"Date of Birth", $P{dateOfBirth}}
),
new String[]{"c1", "c2"}
)
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_15" pageWidth="595" pageHeight="842" whenNoDataType="AllSectionsNoDetail" columnWidth="555" leftMargin="20" rightMargin="20" topMargin="20" bottomMargin="20" uuid="342c93fd-9f0b-49db-a6e8-dbc252bbeca4">
<property name="com.jaspersoft.studio.data.defaultdataadapter" value="One Empty Record"/>
<style name="Table_TD" mode="Opaque" backcolor="#FFFFFF">
<box>
<pen lineWidth="0.5" lineColor="#000000"/>
<topPen lineWidth="0.5" lineColor="#000000"/>
<leftPen lineWidth="0.5" lineColor="#000000"/>
<bottomPen lineWidth="0.5" lineColor="#000000"/>
<rightPen lineWidth="0.5" lineColor="#000000"/>
</box>
</style>
<subDataset name="Dataset" uuid="604ce812-0b69-47fa-862f-c6b4356c6b62">
<queryString>
<![CDATA[]]>
</queryString>
<field name="c1" class="java.lang.String"/>
<field name="c2" class="java.lang.String"/>
</subDataset>
<parameter name="name" class="java.lang.String">
<defaultValueExpression><![CDATA["Nasser Ali"]]></defaultValueExpression>
</parameter>
<parameter name="dateOfBirth" class="java.lang.String">
<defaultValueExpression><![CDATA["1985-10-07"]]></defaultValueExpression>
</parameter>
<queryString>
<![CDATA[]]>
</queryString>
<title>
<band height="61" splitType="Stretch">
<staticText>
<reportElement mode="Opaque" x="0" y="1" width="400" height="30" forecolor="#FFFFFF" backcolor="#000000" uuid="56949b5f-9b21-4f88-9660-ddccce0e7cad"/>
<textElement textAlignment="Center" verticalAlignment="Middle">
<font size="12" isBold="true"/>
</textElement>
<text><![CDATA[Personal information]]></text>
</staticText>
<componentElement>
<reportElement x="0" y="31" width="400" height="30" uuid="7a9309f0-4b5f-4c01-9b0a-611807b01f96">
<property name="com.jaspersoft.studio.layout" value="com.jaspersoft.studio.editor.layout.VerticalRowLayout"/>
<property name="com.jaspersoft.studio.table.style.table_header" value="Table_TH"/>
<property name="com.jaspersoft.studio.table.style.column_header" value="Table_CH"/>
<property name="com.jaspersoft.studio.table.style.detail" value="Table_TD"/>
<property name="com.jaspersoft.studio.unit.width" value="px"/>
</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="Dataset" uuid="f682c987-479a-40f9-8b97-bf07577e67fa">
<dataSourceExpression><![CDATA[new net.sf.jasperreports.engine.data.ListOfArrayDataSource(Arrays.asList(new String[]{"Name", $P{name}}, new String[]{"Date of Birth", $P{dateOfBirth}}),new String[]{"c1", "c2"})]]></dataSourceExpression>
</datasetRun>
<jr:column width="200" uuid="c087b83b-e6f9-4366-b655-eb7c14e35745">
<property name="com.jaspersoft.studio.components.table.model.column.name" value="Column1"/>
<jr:detailCell style="Table_TD" height="30">
<textField>
<reportElement x="0" y="0" width="200" height="30" uuid="dce0c9d6-ec99-4cbb-b981-73d3dff1b67b"/>
<box leftPadding="5"/>
<textElement verticalAlignment="Middle">
<font size="12"/>
</textElement>
<textFieldExpression><![CDATA[$F{c1}]]></textFieldExpression>
</textField>
</jr:detailCell>
</jr:column>
<jr:column width="200" uuid="dad64648-00cb-46ff-9f74-216170605bf6">
<property name="com.jaspersoft.studio.components.table.model.column.name" value="Column2"/>
<jr:detailCell style="Table_TD" height="30">
<property name="com.jaspersoft.studio.unit.width" value="px"/>
<textField>
<reportElement x="0" y="0" width="200" height="30" forecolor="#FF0400" uuid="05d673a9-93d4-4b3e-a4eb-6fd5fd171b30"/>
<box leftPadding="5"/>
<textElement verticalAlignment="Middle">
<font size="12"/>
</textElement>
<textFieldExpression><![CDATA[$F{c2}]]></textFieldExpression>
</textField>
</jr:detailCell>
</jr:column>
</jr:table>
</componentElement>
</band>
</title>
</jasperReport>
Output:

How to merge cells in same column [duplicate]

In jrxml design for my report, I have a column in my detail section that is printing same thing for a specific group. For Example, if i have a country column USA and the next column contains its states. Country USA repeats for each entry . So i need to merge the country cells has USA value. I need to merge all the cells of column has same value and should display it as a single cell and it should align its text vertically and horizontally center. Anybody help me how can i achieve this by using jrxml?
Everything is in the Detail band.
I am working to get a report like in the below picture
UPDATED:
From Peter's answer I have one doubt, if my xml is like:
<report>
<row1>
<country>INDIA</country>
<state>Haryana</state>
</row1>
<row2>
<country>INDIA</country>
<state>Punjab</state>
</row2>
<row3>
<country>INDIA</country>
<state>Maharashtra</state>
</row3>
</report>
How can I create the report if my xml is like above?
You can fairly easy achieve text vertically aligned at top by using isPrintRepeatedValues="false", setting borders correctly (only top, using empty cell with only left, adding line to columnFooter).
To achieve "text vertically aligned at center" use a subreport for the other columns and set stretchType="RelativeToBandHeight" on your rowspan column.
Note you need in this case change your datasource (main report, country by country, subreport all states relative to country)
EDIT: Comment: This not works in detail band. Petter – #Tinoy Malayil.
I include a runnable example for text vertically aligned at center:
Datasource xml:
<report>
<country>
<name>INDIA</name>
<states>
<state>Haryana</state>
<state>Punjab</state>
<state>Maharashtra</state>
<state>Karnataka</state>
<state>TamilNadu</state>
</states>
</country>
<country>
<name>USA</name>
<states>
<state>Alabama</state>
<state>Washington</state>
<state>Alaska</state>
<state>Texas</state>
</states>
</country>
</report>
Main report:, country.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="Country" pageWidth="595" pageHeight="842" whenNoDataType="AllSectionsNoDetail" columnWidth="555" leftMargin="20" rightMargin="20" topMargin="30" bottomMargin="30" uuid="dbc44bea-4f8e-4072-9c94-8442f3093aa0">
<parameter name="SUBREPORT_DIR" class="java.lang.String" isForPrompting="false">
<defaultValueExpression><![CDATA["C:\\fullPath\\to\\Your\\subreport\\"]]></defaultValueExpression>
</parameter>
<queryString language="xPath">
<![CDATA[report/country]]>
</queryString>
<field name="name" class="java.lang.String">
<fieldDescription><![CDATA[name]]></fieldDescription>
</field>
<background>
<band/>
</background>
<columnHeader>
<band height="20">
<staticText>
<reportElement x="0" y="0" width="177" height="20" uuid="d4eb7868-2f74-4713-abca-a176c47927e1"/>
<box>
<pen lineWidth="0.25"/>
<topPen lineWidth="0.25"/>
<leftPen lineWidth="0.25"/>
<bottomPen lineWidth="0.25"/>
<rightPen lineWidth="0.25"/>
</box>
<textElement textAlignment="Center" verticalAlignment="Middle"/>
<text><![CDATA[COUNTRY]]></text>
</staticText>
<staticText>
<reportElement x="177" y="0" width="200" height="20" uuid="98cbcff7-6b24-43bd-a2df-39cc07e56487"/>
<box>
<pen lineWidth="0.25"/>
<topPen lineWidth="0.25"/>
<leftPen lineWidth="0.25"/>
<bottomPen lineWidth="0.25"/>
<rightPen lineWidth="0.25"/>
</box>
<textElement textAlignment="Center" verticalAlignment="Middle"/>
<text><![CDATA[STATE]]></text>
</staticText>
</band>
</columnHeader>
<detail>
<band height="20">
<textField>
<reportElement stretchType="RelativeToBandHeight" x="0" y="0" width="177" height="20" uuid="1bbab3e7-f8a3-48c9-b28e-2a6d2a68b755"/>
<box topPadding="0" leftPadding="0">
<pen lineWidth="0.25"/>
<topPen lineWidth="0.25"/>
<leftPen lineWidth="0.25"/>
<bottomPen lineWidth="0.25"/>
<rightPen lineWidth="0.25"/>
</box>
<textElement textAlignment="Center" verticalAlignment="Middle"/>
<textFieldExpression><![CDATA[$F{name}]]></textFieldExpression>
</textField>
<subreport>
<reportElement x="177" y="0" width="200" height="20" uuid="6314908a-006d-4a5b-9137-a056eb205529"/>
<dataSourceExpression><![CDATA[((net.sf.jasperreports.engine.data.JRXmlDataSource)$P{REPORT_DATA_SOURCE}).subDataSource("/country/states/state")]]></dataSourceExpression>
<subreportExpression><![CDATA[$P{SUBREPORT_DIR} + "country_subreport.jasper"]]></subreportExpression>
</subreport>
</band>
</detail>
</jasperReport>
subreport, country_subreport.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="country_subreport" language="java" pageWidth="200" pageHeight="500" columnWidth="200" leftMargin="0" rightMargin="0" topMargin="0" bottomMargin="0" uuid="c9795fb7-39e0-4aa6-8926-2f019c4af84e">
<property name="ireport.zoom" value="1.0"/>
<property name="ireport.x" value="0"/>
<property name="ireport.y" value="0"/>
<queryString language="xPath">
<![CDATA[/report/country/states/state]]>
</queryString>
<field name="state" class="java.lang.String">
<fieldDescription><![CDATA[child::text()]]></fieldDescription>
</field>
<detail>
<band height="20" splitType="Stretch">
<textField>
<reportElement x="0" y="0" width="200" height="20" uuid="dc0a9dda-b940-4752-ad91-31420c4ce729"/>
<box topPadding="2" leftPadding="2">
<pen lineWidth="0.25"/>
<topPen lineWidth="0.25"/>
<leftPen lineWidth="0.25"/>
<bottomPen lineWidth="0.25"/>
<rightPen lineWidth="0.25"/>
</box>
<textElement verticalAlignment="Middle"/>
<textFieldExpression><![CDATA[$F{state}]]></textFieldExpression>
</textField>
</band>
</detail>

The vertical alignment is not working for several merged text fields (isPrintRepeatedValues=false) [duplicate]

In jrxml design for my report, I have a column in my detail section that is printing same thing for a specific group. For Example, if i have a country column USA and the next column contains its states. Country USA repeats for each entry . So i need to merge the country cells has USA value. I need to merge all the cells of column has same value and should display it as a single cell and it should align its text vertically and horizontally center. Anybody help me how can i achieve this by using jrxml?
Everything is in the Detail band.
I am working to get a report like in the below picture
UPDATED:
From Peter's answer I have one doubt, if my xml is like:
<report>
<row1>
<country>INDIA</country>
<state>Haryana</state>
</row1>
<row2>
<country>INDIA</country>
<state>Punjab</state>
</row2>
<row3>
<country>INDIA</country>
<state>Maharashtra</state>
</row3>
</report>
How can I create the report if my xml is like above?
You can fairly easy achieve text vertically aligned at top by using isPrintRepeatedValues="false", setting borders correctly (only top, using empty cell with only left, adding line to columnFooter).
To achieve "text vertically aligned at center" use a subreport for the other columns and set stretchType="RelativeToBandHeight" on your rowspan column.
Note you need in this case change your datasource (main report, country by country, subreport all states relative to country)
EDIT: Comment: This not works in detail band. Petter – #Tinoy Malayil.
I include a runnable example for text vertically aligned at center:
Datasource xml:
<report>
<country>
<name>INDIA</name>
<states>
<state>Haryana</state>
<state>Punjab</state>
<state>Maharashtra</state>
<state>Karnataka</state>
<state>TamilNadu</state>
</states>
</country>
<country>
<name>USA</name>
<states>
<state>Alabama</state>
<state>Washington</state>
<state>Alaska</state>
<state>Texas</state>
</states>
</country>
</report>
Main report:, country.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="Country" pageWidth="595" pageHeight="842" whenNoDataType="AllSectionsNoDetail" columnWidth="555" leftMargin="20" rightMargin="20" topMargin="30" bottomMargin="30" uuid="dbc44bea-4f8e-4072-9c94-8442f3093aa0">
<parameter name="SUBREPORT_DIR" class="java.lang.String" isForPrompting="false">
<defaultValueExpression><![CDATA["C:\\fullPath\\to\\Your\\subreport\\"]]></defaultValueExpression>
</parameter>
<queryString language="xPath">
<![CDATA[report/country]]>
</queryString>
<field name="name" class="java.lang.String">
<fieldDescription><![CDATA[name]]></fieldDescription>
</field>
<background>
<band/>
</background>
<columnHeader>
<band height="20">
<staticText>
<reportElement x="0" y="0" width="177" height="20" uuid="d4eb7868-2f74-4713-abca-a176c47927e1"/>
<box>
<pen lineWidth="0.25"/>
<topPen lineWidth="0.25"/>
<leftPen lineWidth="0.25"/>
<bottomPen lineWidth="0.25"/>
<rightPen lineWidth="0.25"/>
</box>
<textElement textAlignment="Center" verticalAlignment="Middle"/>
<text><![CDATA[COUNTRY]]></text>
</staticText>
<staticText>
<reportElement x="177" y="0" width="200" height="20" uuid="98cbcff7-6b24-43bd-a2df-39cc07e56487"/>
<box>
<pen lineWidth="0.25"/>
<topPen lineWidth="0.25"/>
<leftPen lineWidth="0.25"/>
<bottomPen lineWidth="0.25"/>
<rightPen lineWidth="0.25"/>
</box>
<textElement textAlignment="Center" verticalAlignment="Middle"/>
<text><![CDATA[STATE]]></text>
</staticText>
</band>
</columnHeader>
<detail>
<band height="20">
<textField>
<reportElement stretchType="RelativeToBandHeight" x="0" y="0" width="177" height="20" uuid="1bbab3e7-f8a3-48c9-b28e-2a6d2a68b755"/>
<box topPadding="0" leftPadding="0">
<pen lineWidth="0.25"/>
<topPen lineWidth="0.25"/>
<leftPen lineWidth="0.25"/>
<bottomPen lineWidth="0.25"/>
<rightPen lineWidth="0.25"/>
</box>
<textElement textAlignment="Center" verticalAlignment="Middle"/>
<textFieldExpression><![CDATA[$F{name}]]></textFieldExpression>
</textField>
<subreport>
<reportElement x="177" y="0" width="200" height="20" uuid="6314908a-006d-4a5b-9137-a056eb205529"/>
<dataSourceExpression><![CDATA[((net.sf.jasperreports.engine.data.JRXmlDataSource)$P{REPORT_DATA_SOURCE}).subDataSource("/country/states/state")]]></dataSourceExpression>
<subreportExpression><![CDATA[$P{SUBREPORT_DIR} + "country_subreport.jasper"]]></subreportExpression>
</subreport>
</band>
</detail>
</jasperReport>
subreport, country_subreport.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="country_subreport" language="java" pageWidth="200" pageHeight="500" columnWidth="200" leftMargin="0" rightMargin="0" topMargin="0" bottomMargin="0" uuid="c9795fb7-39e0-4aa6-8926-2f019c4af84e">
<property name="ireport.zoom" value="1.0"/>
<property name="ireport.x" value="0"/>
<property name="ireport.y" value="0"/>
<queryString language="xPath">
<![CDATA[/report/country/states/state]]>
</queryString>
<field name="state" class="java.lang.String">
<fieldDescription><![CDATA[child::text()]]></fieldDescription>
</field>
<detail>
<band height="20" splitType="Stretch">
<textField>
<reportElement x="0" y="0" width="200" height="20" uuid="dc0a9dda-b940-4752-ad91-31420c4ce729"/>
<box topPadding="2" leftPadding="2">
<pen lineWidth="0.25"/>
<topPen lineWidth="0.25"/>
<leftPen lineWidth="0.25"/>
<bottomPen lineWidth="0.25"/>
<rightPen lineWidth="0.25"/>
</box>
<textElement verticalAlignment="Middle"/>
<textFieldExpression><![CDATA[$F{state}]]></textFieldExpression>
</textField>
</band>
</detail>

JRXML - Eliminating repeated header on the bottom

We've got a problem when printing some PDF reports using JasperReports. These reports are basically a breakdown of all the sales made to a specific client over the course of the years.
We take information from a DB, transform it using Java, and print the reports in PDF. The problem is, in some rare cases, some headers appear repeated at the bottom of each page:
Ideally, we should be able to omit that loose header and keep only the one on the new page, but I can't seem to do it, at least via TIBCO Jaspersoft Studio.
I don't actually know much about these reports, but any information you need to help, feel free to ask.
Thanks in advance.
EDIT: Following Petter Friberg's comment, here's parts of the JRXML being used in this report. I omitted some parts that follow the same properties, but i think this should be clear enough.
<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="Historique" language="groovy" pageWidth="595" pageHeight="842" columnWidth="483" leftMargin="56" rightMargin="56" topMargin="43" bottomMargin="43" isSummaryWithPageHeaderAndFooter="true" resourceBundle="reportLabels" whenResourceMissingType="Empty" uuid="80db05e1-8ca3-483d-86cc-5947dc62296b">
<property name="ireport.zoom" value="1.0"/>
<property name="ireport.x" value="0"/>
<property name="ireport.y" value="0"/>
<property name="com.jaspersoft.studio.unit." value="pixel"/>
<property name="com.jaspersoft.studio.layout" value="com.jaspersoft.studio.editor.layout.VerticalRowLayout"/>
<property name="com.jaspersoft.studio.unit.topMargin" value="mm"/>
<property name="com.jaspersoft.studio.unit.bottomMargin" value="mm"/>
<property name="com.jaspersoft.studio.unit.leftMargin" value="mm"/>
<property name="com.jaspersoft.studio.unit.rightMargin" value="mm"/>
<property name="com.jaspersoft.studio.unit.pageHeight" value="pixel"/>
<property name="com.jaspersoft.studio.unit.pageWidth" value="pixel"/>
<property name="com.jaspersoft.studio.unit.columnWidth" value="pixel"/>
<property name="com.jaspersoft.studio.unit.columnSpacing" value="pixel"/>
<template><![CDATA["/jasper/styles_letter.jrtx"]]></template>
<style name="Table Group Header" mode="Opaque" forecolor="#000000" backcolor="#99CCFF" vTextAlign="Middle" fontName="Arial" fontSize="10" isBold="true" pdfFontName="Helvetica-Bold"/>
<!-- ... multiple styles -->
<parameter name="title" class="java.lang.String"/>
<!-- ... multiple parameters-->
<parameter name="addressCity" class="java.lang.String"/>
<field name="reduction" class="java.lang.String">
<fieldDescription><![CDATA[reduction]]></fieldDescription>
</field>
<!-- ... multiple fields -->
<field name="year" class="java.lang.String"/>
<group name="DescriptionGroup">
<groupExpression><![CDATA[$F{year}]]></groupExpression>
<groupHeader>
<band height="30">
<property name="com.jaspersoft.studio.unit.height" value="pixel"/>
<textField evaluationTime="Group" evaluationGroup="DescriptionGroup" bookmarkLevel="2">
<reportElement style="Table Group Header" mode="Opaque" x="0" y="0" width="483" height="15" printWhenGroupChanges="DescriptionGroup" backcolor="#B0B0B0" uuid="f626bb36-a919-48b9-98b3-756d1ce9812b">
<property name="local_mesure_unitx" value="pixel"/>
<property name="com.jaspersoft.studio.unit.x" value="px"/>
<property name="com.jaspersoft.studio.unit.height" value="pixel"/>
<printWhenExpression><![CDATA[new Boolean($P{emptyList} != true)]]></printWhenExpression>
</reportElement>
<box leftPadding="10">
<topPen lineWidth="0.0" lineStyle="Solid" lineColor="#000000"/>
<leftPen lineWidth="0.0" lineStyle="Solid" lineColor="#000000"/>
<bottomPen lineWidth="0.5" lineStyle="Solid" lineColor="#000000"/>
<rightPen lineWidth="0.0" lineStyle="Solid" lineColor="#000000"/>
</box>
<textElement markup="none">
<font size="9" isBold="true"/>
</textElement>
<textFieldExpression><![CDATA[$F{year}]]></textFieldExpression>
</textField>
<!-- ... multiple text fields following the same principle -->
</band>
</groupHeader>
</group>
<background>
<band splitType="Stretch"/>
</background>
<title>
<!-- this only appears in the first page, has all the customer info -->
</title>
<columnHeader>
<band splitType="Stretch"/>
</columnHeader>
<detail>
<band height="25" splitType="Stretch">
<property name="com.jaspersoft.studio.layout" value="com.jaspersoft.studio.editor.layout.HorizontalRowLayout"/>
<property name="com.jaspersoft.studio.unit.height" value="pixel"/>
<textField pattern="" isBlankWhenNull="true">
<reportElement style="Zebra" mode="Opaque" x="0" y="0" width="130" height="25" uuid="234d3832-bd30-40a0-b8e5-eac964158000">
<property name="local_mesure_unitheight" value="pixel"/>
<property name="local_mesure_unitx" value="pixel"/>
<property name="com.jaspersoft.studio.unit.x" value="px"/>
<property name="com.jaspersoft.studio.unit.height" value="pixel"/>
<printWhenExpression><![CDATA[new Boolean($P{emptyList} != true)]]></printWhenExpression>
</reportElement>
<textElement>
<font size="8" isBold="false"/>
<paragraph leftIndent="3"/>
</textElement>
<textFieldExpression><![CDATA[$F{article}]]></textFieldExpression>
</textField>
<!-- ... multiple fields following the same principle. this is the body of each sub-table, showing the info for each year -->
</band>
</detail>
<pageFooter>
<band height="25" splitType="Stretch">
<!-- ... -->
</band>
</pageFooter>
<summary>
<band height="40" splitType="Stretch">
<!-- ... shows a summary of all the info shown on each table -->
</band>
</summary>
</jasperReport>
Thanks in advance.
You are using a group the generate the header, so you can use this attribute minHeightToStartNewPage, to determine how much space needs to remain otherwise break to new page.
<group name="DescriptionGroup" minHeightToStartNewPage="60">
or if you like to force it to always start on new page
<group name="DescriptionGroup" isStartNewPage="true">

Jasper Report merging cells in jasper table results in unwanted coulmn

i am fairly new to jasper report. I need to merge cells in jasper table and i have managed some portion of it. See following image.
as u can see that the there is empty cells. I need a single cells instead of multiple empty cells. Can you guys help me with me. I am stuck. I am posting my 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="report1" language="groovy" pageWidth="595" pageHeight="842" columnWidth="555" leftMargin="20" rightMargin="20" topMargin="20" bottomMargin="20" uuid="9c6d12ac-438a-4209-b92b-fe8357e9a0ab">
<property name="ireport.zoom" value="1.0"/>
<property name="ireport.x" value="0"/>
<property name="ireport.y" value="2"/>
<style name="table">
<box>
<pen lineWidth="1.0" lineColor="#000000"/>
</box>
</style>
<style name="table_TH" mode="Opaque" backcolor="#F0F8FF">
<box>
<pen lineWidth="0.5" lineColor="#000000"/>
</box>
</style>
<style name="table_CH" mode="Opaque" backcolor="#BFE1FF">
<box>
<pen lineWidth="0.5" lineColor="#000000"/>
</box>
</style>
<style name="table_TD" mode="Opaque" backcolor="#FFFFFF">
<box>
<pen lineWidth="0.5" lineColor="#000000"/>
</box>
</style>
<subDataset name="medication" uuid="540773d1-98fb-48a3-9b89-a187c3e37e8a">
<queryString language="SQL">
<![CDATA[SELECT m.ID,m.medication_name,d.dose_time FROM medication m
LEFT JOIN dose_time d ON m.ID = d.medication_id;]]>
</queryString>
<field name="ID" class="java.lang.Integer">
<fieldDescription><![CDATA[]]></fieldDescription>
</field>
<field name="medication_name" class="java.lang.String">
<fieldDescription><![CDATA[]]></fieldDescription>
</field>
<field name="dose_time" class="java.lang.String">
<fieldDescription><![CDATA[]]></fieldDescription>
</field>
<group name="ID">
<groupExpression><![CDATA[$F{ID}]]></groupExpression>
</group>
</subDataset>
<queryString>
<![CDATA[select mdt.ID,mdt.medication_name,dt.dose_time from medication mdt left join dose_time dt on mdt.ID = dt.medication_id;]]>
</queryString>
<field name="ID" class="java.lang.Integer">
<fieldDescription><![CDATA[]]></fieldDescription>
</field>
<field name="medication_name" class="java.lang.String">
<fieldDescription><![CDATA[]]></fieldDescription>
</field>
<field name="dose_time" class="java.lang.String">
<fieldDescription><![CDATA[]]></fieldDescription>
</field>
<background>
<band splitType="Stretch"/>
</background>
<columnHeader>
<band height="61" splitType="Stretch"/>
</columnHeader>
<detail>
<band height="125" splitType="Stretch">
<componentElement>
<reportElement uuid="b80b6480-79a3-4c7a-b7e6-73e8df552d6a" key="table" style="table" x="0" y="0" width="555" height="125">
<printWhenExpression><![CDATA[$V{REPORT_COUNT} == 1]]></printWhenExpression>
</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="medication" uuid="966ad176-a042-4a9f-b4fe-3c5cf2c43370">
<connectionExpression><![CDATA[$P{REPORT_CONNECTION}]]></connectionExpression>
</datasetRun>
<jr:column width="90" uuid="1674ad29-29a8-47d3-9bf9-fb233d836dcc">
<jr:groupFooter groupName="ID">
<jr:cell height="0" rowSpan="1"/>
</jr:groupFooter>
<jr:columnHeader style="table_CH" height="32" rowSpan="1">
<staticText>
<reportElement uuid="1e2c5349-4cc9-4caf-9d7f-ac34dfbdb1b4" x="0" y="0" width="90" height="30"/>
<textElement/>
<text><![CDATA[Medication Name]]></text>
</staticText>
</jr:columnHeader>
<jr:detailCell height="30" rowSpan="1">
<textField>
<reportElement uuid="cfeb2bce-6f8d-413c-8f4e-cfbe61cc2d24" style="table_TD" x="0" y="0" width="90" height="30">
<printWhenExpression><![CDATA[$V{ID_COUNT}==1]]></printWhenExpression>
</reportElement>
<box leftPadding="0">
<pen lineWidth="0.5"/>
<topPen lineWidth="0.5"/>
<leftPen lineWidth="0.5"/>
<bottomPen lineWidth="0.5"/>
<rightPen lineWidth="0.5"/>
</box>
<textElement/>
<textFieldExpression><![CDATA[$F{ID}+$F{medication_name}]]></textFieldExpression>
</textField>
</jr:detailCell>
</jr:column>
<jr:column width="90" uuid="193e3bc0-bdba-42ec-824a-cb0e7b37b7d1">
<jr:columnHeader style="table_CH" height="32" rowSpan="1">
<staticText>
<reportElement uuid="c165e681-8db2-49af-9046-e3db70bfe0cf" x="0" y="0" width="90" height="30"/>
<textElement/>
<text><![CDATA[Doses Time]]></text>
</staticText>
</jr:columnHeader>
<jr:detailCell style="table_TD" height="30" rowSpan="1">
<textField>
<reportElement uuid="78fff516-49ab-4e1d-aa06-4c97d48bad0d" x="0" y="0" width="90" height="30"/>
<textElement/>
<textFieldExpression><![CDATA[$F{dose_time}]]></textFieldExpression>
</textField>
</jr:detailCell>
</jr:column>
</jr:table>
</componentElement>
</band>
</detail>
</jasperReport>
I see two possible solutions here:
Create a group band and group by "Medication Name" you will have empty cells but it will look cool :)
Use some SQL kung-fu with the function concat_ws() to get the "Doses Time" in the same field as a list.
Have fun and I hope it helps.