How to split details across multiple columns while programmatically appending 'continuation' message for subsequent sections? - jasper-reports

I have a customer request to split details of personal information (name, address, secondary addresses, etc) across multiple columns, if the dynamic size does not fit in the current column. As a caveat, the name field, followed by the word '(Continued)', is desired, as the title for the segments in subsequent columns.
Is this behavior possible with jasper-reports?
I have tried toggling an 'inBetween' flag with the beforeDetailEval() and afterDetailEval() hooks, checking that flag in the column header band, to optionally reprint the name + 'Continued', but the column header always calls the scriptlet method AFTER the afterDetailEval() method (does not make sense to my little mind), failing since the 'inBetween' flag is reset to false.
(Note: Detail band has been set with splitType to both 'Immediate' and 'Stretch', but neither approach has behaved as expected. The entire band just gets restarted at the beginning of the next column)
Is this possible, and if so, are there any suggestions for creative solutions for this scenario?
Also, there is strange behavior displaying where if a detail is split across multiple columns, the first part of the detail (up to the subreport element)is duplicated on the following column. This behavior is also undesirable to the customer, and needs to be adjusted so nothing (except the title) is duplicated.
This is the syntax desired by the customer:
Name 1 Name 2
Address 1 (Continued)
City 1 AL – Address 3
State 1 AL - City 3
Zip 1 AL - State 3
Additional Locations: AL - Zip 3
AL-Address 1 ...
AL-City 1
AL-State 1
AL-Zip 1
AL-Address 2
AL-City 2
AL-State 2
AL-Zip 2
Name 2
Address 2
City 2
State 2
Zip 2
Additional Locations:
AL-Address 1
AL – City 1
AL-State 1
AL – Zip 1
AL – Address 2
AL – City 2
AL – State 2
AL – Zip 2
This is what we are actually getting:
Name1 Name1
Address1 Address1
City1 City1
State1 State1
Zip1 Zip1
Additional Locations Additional Locations
AL-Name1 AL-City2
AL-Address1 AL-State2
AL-City1 AL-State2
AL-State1
AL-Zip1
AL-Name2
AL-Address2
This is a sample main jrxml file:
<?xml version="1.0" encoding="UTF-8"?>
<!-- Created with Jaspersoft Studio version 6.3.1.final using JasperReports Library version 6.3.1 -->
<!-- 2017-06-22T09:48:08 -->
<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" columnCount="2" pageWidth="595" pageHeight="842" columnWidth="555" leftMargin="20" rightMargin="20" topMargin="20" bottomMargin="20" scriptletClass="path.to.my.scriptlet" uuid="af53d807-7975-4ff7-bfc5-e438944aa795">
<property name="com.jaspersoft.studio.data.defaultdataadapter" value="One Empty Record"/>
<queryString>
<![CDATA[]]>
</queryString>
<field name="Name" class="java.lang.String"/>
<field name="Address" class="java.lang.String"/>
<field name="City" class="java.lang.String"/>
<field name="State" class="java.lang.String"/>
<field name="Zip" class="java.lang.String"/>
<field name="AdditionalLocations" class="java.util.List"/>
<variable name="IN_MIDDLE_OF_DETAIL" class="java.lang.Boolean" calculation="System">
<initialValueExpression><![CDATA[Boolean.False]]></initialValueExpression>
</variable>
<columnHeader>
<band height="74" splitType="Stretch">
<textField isBlankWhenNull="true">
<reportElement x="-10" y="0" width="100" height="30" uuid="258dce49-fb61-4887-bb30-69e80e96d8f1">
<printWhenExpression><![CDATA[$V{IN_MIDDLE_OF_DETAIL}]]></printWhenExpression>
</reportElement>
<textFieldExpression><![CDATA[$F{Name}]]></textFieldExpression>
</textField>
<textField>
<reportElement x="-10" y="40" width="100" height="30" uuid="c18b2fab-900b-4641-aaef-2520510a3510">
<printWhenExpression><![CDATA[$V{IN_MIDDLE_OF_DETAIL}]]></printWhenExpression>
</reportElement>
<textFieldExpression><![CDATA["(CONTINUED)"]]></textFieldExpression>
</textField>
</band>
</columnHeader>
<detail>
<band height="426" splitType="Stretch">
<textField>
<reportElement x="0" y="10" width="100" height="30" uuid="853a1b0d-a49e-45c4-8183-83cfd69bf5af"/>
<textFieldExpression><![CDATA[$F{Name}]]></textFieldExpression>
</textField>
<textField>
<reportElement x="0" y="50" width="100" height="30" uuid="46697c6d-1c2f-422b-9170-6b2f36ce13ba"/>
<textFieldExpression><![CDATA[$F{Address}]]></textFieldExpression>
</textField>
<textField>
<reportElement x="0" y="90" width="100" height="30" uuid="31730cd5-0b17-452e-8a22-d16ea2061605"/>
<textFieldExpression><![CDATA[$F{City}]]></textFieldExpression>
</textField>
<textField>
<reportElement x="0" y="120" width="100" height="30" uuid="b4a4c671-dc63-41b4-b080-9ad5b750bb58"/>
<textFieldExpression><![CDATA[$F{State}]]></textFieldExpression>
</textField>
<textField>
<reportElement x="0" y="160" width="100" height="30" uuid="8f8bec7c-3d4a-466b-8b02-2bb82e61904d"/>
<textFieldExpression><![CDATA[$F{Zip}]]></textFieldExpression>
</textField>
<subreport>
<reportElement x="0" y="220" width="100" height="110" uuid="8ef583fd-fa23-47d8-80d0-90de4f6478a0"/>
<dataSourceExpression><![CDATA[new net.sf.jasperreports.engine.data.JRBeanCollectionDataSource($F{AdditionalLocations})]]></dataSourceExpression>
<subreportExpression><![CDATA["Blank_A4_1.jasper"]]></subreportExpression>
</subreport>
<staticText>
<reportElement x="10" y="198" width="100" height="30" uuid="4887e0c1-3da2-4350-9454-4a3e33c0fe71"/>
<text><![CDATA[Additional Locations]]></text>
</staticText>
</band>
</detail>
</jasperReport>
This is the sample subreport jrxml file:
<?xml version="1.0" encoding="UTF-8"?>
<!-- Created with Jaspersoft Studio version 6.3.1.final using JasperReports Library version 6.3.1 -->
<!-- 2017-06-22T10:39:43 -->
<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_1" pageWidth="595" pageHeight="842" columnWidth="555" leftMargin="20" rightMargin="20" topMargin="20" bottomMargin="20" uuid="9b8a1d93-2ee6-4d29-b9ec-7c56a3917729">
<queryString>
<![CDATA[]]>
</queryString>
<field name="Address" class="java.lang.String"/>
<field name="City" class="java.lang.String"/>
<field name="State" class="java.lang.String"/>
<field name="Zip" class="java.lang.String"/>
<detail>
<band height="168" splitType="Stretch">
<textField isBlankWhenNull="true">
<reportElement x="0" y="10" width="100" height="30" uuid="3d74e624-6b6f-40e9-87d2-ddb5022668b2"/>
<textFieldExpression><![CDATA[$F{Address}]]></textFieldExpression>
</textField>
<textField>
<reportElement x="0" y="50" width="100" height="30" uuid="5df31fa3-38ee-44a4-8931-e8eef45fb7a6"/>
<textFieldExpression><![CDATA[$F{City}]]></textFieldExpression>
</textField>
<textField>
<reportElement x="0" y="89" width="100" height="30" uuid="964a282f-54c7-44a3-954d-27d1c70d3d0c"/>
<textFieldExpression><![CDATA[$F{State}]]></textFieldExpression>
</textField>
<textField>
<reportElement x="0" y="130" width="100" height="30" uuid="e1349222-d945-4dec-8454-e2d6e3fb6a2a"/>
<textFieldExpression><![CDATA[$F{Zip}]]></textFieldExpression>
</textField>
</band>
</detail>
</jasperReport>
This is the basic scriptlet code to toggle the value of IN_MIDDLE_OF_DETAIL:
#Override
public void beforeDetailEval() throws JRScriptletException
{
setVariableValue("IN_MIDDLE_OF_DETAIL", Boolean.TRUE)
}
#Override
public void afterDetailEval() throws JRScriptletException
{
setVariableValue("IN_MIDDLE_OF_DETAIL", Boolean.FALSE)
}

Drop the scriptlet, there is no need for this, lets use the fact that subreport's has its own page count, hence when it breaks in main report it counts a page
The solution I would use is the pageHeader band in the subreport with a printWhenExpression on page number (>1).
Which means that the text that you like to display when subreport splits to new "page" (name and "Continue") goes into pageHeader of the subreport and should be printed on all subreport "pages" except the first one.
Since name does not seems to be part of the subreport datasource I will pass this as a parameter to the subreport.
Code in subreport to display header when page > 1
<pageHeader>
<band height="44">
<printWhenExpression><![CDATA[$V{PAGE_NUMBER}>1]]></printWhenExpression>
<textField>
<reportElement x="0" y="0" width="220" height="20" uuid="8cce4cab-6ccf-4ddb-b1f1-508dc97bfcfe"/>
<textElement verticalAlignment="Middle">
<font isBold="true"/>
</textElement>
<textFieldExpression><![CDATA[$P{name}]]></textFieldExpression>
</textField>
<textField>
<reportElement x="0" y="20" width="220" height="19" uuid="c18b2fab-900b-4641-aaef-2520510a3510"/>
<textElement verticalAlignment="Middle">
<font isItalic="true"/>
</textElement>
<textFieldExpression><![CDATA["(Continued)"]]></textFieldExpression>
</textField>
</band>
</pageHeader>
Example output
I have cut down page height to reduce image
Full example
**main report 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" columnCount="2" pageWidth="595" pageHeight="500" columnWidth="277" leftMargin="20" rightMargin="20" topMargin="20" bottomMargin="20" uuid="af53d807-7975-4ff7-bfc5-e438944aa795">
<queryString>
<![CDATA[]]>
</queryString>
<field name="name" class="java.lang.String"/>
<field name="address" class="java.lang.String"/>
<field name="city" class="java.lang.String"/>
<field name="state" class="java.lang.String"/>
<field name="zip" class="java.lang.String"/>
<field name="additionalLocations" class="java.util.List"/>
<detail>
<band height="141" splitType="Immediate">
<textField isStretchWithOverflow="true">
<reportElement x="0" y="20" width="280" height="20" uuid="46697c6d-1c2f-422b-9170-6b2f36ce13ba">
<property name="com.jaspersoft.studio.unit.height" value="pixel"/>
</reportElement>
<textElement verticalAlignment="Middle"/>
<textFieldExpression><![CDATA[$F{address}]]></textFieldExpression>
</textField>
<textField isStretchWithOverflow="true">
<reportElement x="0" y="40" width="280" height="20" uuid="31730cd5-0b17-452e-8a22-d16ea2061605"/>
<textElement verticalAlignment="Middle"/>
<textFieldExpression><![CDATA[$F{city}]]></textFieldExpression>
</textField>
<textField isStretchWithOverflow="true">
<reportElement x="0" y="60" width="280" height="20" uuid="b4a4c671-dc63-41b4-b080-9ad5b750bb58"/>
<textElement verticalAlignment="Middle"/>
<textFieldExpression><![CDATA[$F{state}]]></textFieldExpression>
</textField>
<textField isStretchWithOverflow="true">
<reportElement x="0" y="80" width="280" height="20" uuid="8f8bec7c-3d4a-466b-8b02-2bb82e61904d"/>
<textElement verticalAlignment="Middle"/>
<textFieldExpression><![CDATA[$F{zip}]]></textFieldExpression>
</textField>
<subreport>
<reportElement x="0" y="120" width="280" height="20" isPrintWhenDetailOverflows="true" uuid="8ef583fd-fa23-47d8-80d0-90de4f6478a0"/>
<subreportParameter name="name">
<subreportParameterExpression><![CDATA[$F{name}]]></subreportParameterExpression>
</subreportParameter>
<dataSourceExpression><![CDATA[new net.sf.jasperreports.engine.data.JRBeanCollectionDataSource($F{additionalLocations})]]></dataSourceExpression>
<subreportExpression><![CDATA["C:/Users/pette/JaspersoftWorkspace/MyReports/SplitSubreport.jasper"]]></subreportExpression>
</subreport>
<staticText>
<reportElement x="0" y="100" width="280" height="20" uuid="4887e0c1-3da2-4350-9454-4a3e33c0fe71"/>
<textElement verticalAlignment="Middle">
<font isItalic="false" isUnderline="true"/>
</textElement>
<text><![CDATA[Additional Locations]]></text>
</staticText>
<textField isStretchWithOverflow="true" isBlankWhenNull="true">
<reportElement x="0" y="0" width="280" height="20" uuid="258dce49-fb61-4887-bb30-69e80e96d8f1"/>
<textElement verticalAlignment="Middle">
<font isBold="true"/>
</textElement>
<textFieldExpression><![CDATA[$F{name}]]></textFieldExpression>
</textField>
</band>
</detail>
</jasperReport>
**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="Blank_A4_1" pageWidth="280" pageHeight="200" columnWidth="280" leftMargin="0" rightMargin="0" topMargin="0" bottomMargin="0" uuid="9b8a1d93-2ee6-4d29-b9ec-7c56a3917729">
<parameter name="name" class="java.lang.String"/>
<queryString>
<![CDATA[]]>
</queryString>
<field name="address" class="java.lang.String"/>
<field name="city" class="java.lang.String"/>
<field name="state" class="java.lang.String"/>
<field name="zip" class="java.lang.String"/>
<pageHeader>
<band height="44">
<printWhenExpression><![CDATA[$V{PAGE_NUMBER}>1]]></printWhenExpression>
<textField>
<reportElement x="0" y="20" width="220" height="19" uuid="c18b2fab-900b-4641-aaef-2520510a3510"/>
<textElement verticalAlignment="Middle">
<font isItalic="true"/>
</textElement>
<textFieldExpression><![CDATA["(Continued)"]]></textFieldExpression>
</textField>
<textField>
<reportElement x="0" y="0" width="220" height="20" uuid="8cce4cab-6ccf-4ddb-b1f1-508dc97bfcfe"/>
<textElement verticalAlignment="Middle">
<font isBold="true"/>
</textElement>
<textFieldExpression><![CDATA[$P{name}]]></textFieldExpression>
</textField>
</band>
</pageHeader>
<detail>
<band height="85" splitType="Stretch">
<textField isStretchWithOverflow="true" isBlankWhenNull="true">
<reportElement x="0" y="-1" width="220" height="21" uuid="3d74e624-6b6f-40e9-87d2-ddb5022668b2"/>
<textElement verticalAlignment="Middle"/>
<textFieldExpression><![CDATA[$F{address}]]></textFieldExpression>
</textField>
<textField isStretchWithOverflow="true">
<reportElement x="0" y="20" width="220" height="20" uuid="5df31fa3-38ee-44a4-8931-e8eef45fb7a6"/>
<textElement verticalAlignment="Middle"/>
<textFieldExpression><![CDATA[$F{city}]]></textFieldExpression>
</textField>
<textField isStretchWithOverflow="true">
<reportElement x="0" y="40" width="220" height="20" uuid="964a282f-54c7-44a3-954d-27d1c70d3d0c"/>
<textElement verticalAlignment="Middle"/>
<textFieldExpression><![CDATA[$F{state}]]></textFieldExpression>
</textField>
<textField isStretchWithOverflow="true">
<reportElement x="0" y="60" width="220" height="20" uuid="e1349222-d945-4dec-8454-e2d6e3fb6a2a"/>
<textElement verticalAlignment="Middle"/>
<textFieldExpression><![CDATA[$F{zip}]]></textFieldExpression>
</textField>
</band>
</detail>
</jasperReport>

Related

The net.sf.jasperreports.style.backcolor attribute is not working for text fields at Frame

In my database I have the hex colour codes for various scenarios and I want to highlight the rows using these variable colours. I have used net.sf.jasperreports.style.backcolor, but all rows have the same background colour which is that of the first row.
<frame>
<reportElement stretchType="ContainerHeight" mode="Opaque" x="0" y="0" width="802" height="12" isRemoveLineWhenBlank="true">
<propertyExpression name="net.sf.jasperreports.style.backcolor"><![CDATA[$F{sp_colour}]]></propertyExpression>
</reportElement>
Looks like the engine is initializing the frame's attribute using the first record from the datasource and using this initial value for all other records (2nd iteration from the result set, 3rd iteration and so on). Probably this is a bug of JasperReports library.
The issue can be solved using several workarounds.
Workaround 1. Using conditional style
The introduction of conditional style is resolving the issue. If we have N unique values of colors we have to add at least N - 1 conditions for style - one condition for one color.
Working example. Datasource
I used csv based datasource for testing report:
team1,team2,color1,color2,duration_color,date
BEL,POR,#0000FF,#7F8C8D,#FFFFFF,"27 June"
ITA,AUT,#0000FF,#7F8C8D,#F2F3F4,"26 June"
FRA,SUI,#7F8C8D,#0000FF,#F6DDCC,"28 June"
CRO,ESP,#7F8C8D,#0000FF,#F2F3F4,"28 June"
SWE,UKR,#7F8C8D,#0000FF,#F2F3F4,"29 June"
ENG,GER,#0000FF,#7F8C8D,#FFFFFF,"29 June"
NED,CZE,#7F8C8D,#0000FF,#FFFFFF,"27 June"
WAL,DEN,#7F8C8D,#0000FF,#FFFFFF,"26 June"
The first row at the file contains the column names and should be skipped (for example using settings of data adapter).
This file contains 3 unique colors (the field duration_color) that will be used as background color.
Working example. Report 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="Backcolor, W1" pageWidth="595" pageHeight="842" whenNoDataType="AllSectionsNoDetail" columnWidth="595" leftMargin="0" rightMargin="0" topMargin="0" bottomMargin="0">
<property name="com.jaspersoft.studio.data.defaultdataadapter" value="colors"/>
<style name="frameStyle">
<conditionalStyle>
<conditionExpression><![CDATA["#FFFFFF".equals($F{duration_color})]]></conditionExpression>
<style/>
</conditionalStyle>
<conditionalStyle>
<conditionExpression><![CDATA["#F2F3F4".equals($F{duration_color})]]></conditionExpression>
<style/>
</conditionalStyle>
<conditionalStyle>
<conditionExpression><![CDATA["#F6DDCC".equals($F{duration_color})]]></conditionExpression>
<style/>
</conditionalStyle>
</style>
<field name="team1" class="java.lang.String"/>
<field name="team2" class="java.lang.String"/>
<field name="color1" class="java.lang.String"/>
<field name="color2" class="java.lang.String"/>
<field name="duration_color" class="java.lang.String"/>
<field name="date" class="java.lang.String"/>
<detail>
<band height="20">
<frame>
<reportElement style="frameStyle" mode="Opaque" x="172" y="0" width="250" height="20">
<propertyExpression name="net.sf.jasperreports.style.backcolor"><![CDATA[$F{duration_color}]]></propertyExpression>
</reportElement>
<textField>
<reportElement x="0" y="0" width="100" height="20"/>
<textElement textAlignment="Left" verticalAlignment="Middle"/>
<textFieldExpression><![CDATA[String.format("Match date: %s", $F{date})]]></textFieldExpression>
</textField>
<textField>
<reportElement x="100" y="0" width="60" height="20">
<propertyExpression name="net.sf.jasperreports.style.forecolor"><![CDATA[$F{color1}]]></propertyExpression>
</reportElement>
<textElement textAlignment="Center" verticalAlignment="Middle"/>
<textFieldExpression><![CDATA[$F{team1}]]></textFieldExpression>
</textField>
<staticText>
<reportElement x="160" y="0" width="30" height="20"/>
<textElement textAlignment="Center" verticalAlignment="Middle"/>
<text><![CDATA[vs]]></text>
</staticText>
<textField>
<reportElement x="190" y="0" width="60" height="20">
<propertyExpression name="net.sf.jasperreports.style.forecolor"><![CDATA[$F{color2}]]></propertyExpression>
</reportElement>
<textElement textAlignment="Center" verticalAlignment="Middle"/>
<textFieldExpression><![CDATA[$F{team2}]]></textFieldExpression>
</textField>
</frame>
</band>
</detail>
<summary>
<band height="50">
<staticText>
<reportElement mode="Opaque" x="20" y="0" width="100" height="20" backcolor="#F2F3F4"/>
<text><![CDATA[Extra time]]></text>
</staticText>
<staticText>
<reportElement mode="Opaque" x="20" y="20" width="100" height="20" backcolor="#F6DDCC"/>
<text><![CDATA[Penalty shootout]]></text>
</staticText>
</band>
</summary>
</jasperReport>
The 3 conditional styles were introduced at frameStyle and this style is applied for the whole frame.
Working example. The output result
I used Jaspersoft Studio (JSS) to generate the output result.
Workaround 2. Applying attributes at elements, not at frame
Another workaround is to apply the net.sf.jasperreports.style.backcolor attribute at all elements (textField and staticText) instead of using the frame's attribute.
Working example. Report template
No need to introduce conditional style in this case.
<?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="Backcolor, W2" pageWidth="595" pageHeight="842" whenNoDataType="AllSectionsNoDetail" columnWidth="595" leftMargin="0" rightMargin="0" topMargin="0" bottomMargin="0">
<property name="com.jaspersoft.studio.data.defaultdataadapter" value="colors"/>
<field name="team1" class="java.lang.String"/>
<field name="team2" class="java.lang.String"/>
<field name="color1" class="java.lang.String"/>
<field name="color2" class="java.lang.String"/>
<field name="duration_color" class="java.lang.String"/>
<field name="date" class="java.lang.String"/>
<detail>
<band height="20">
<frame>
<reportElement x="172" y="0" width="250" height="20"/>
<textField>
<reportElement mode="Opaque" x="0" y="0" width="100" height="20"/>
<textElement textAlignment="Left" verticalAlignment="Middle"/>
<textFieldExpression><![CDATA[String.format("Match date: %s", $F{date})]]></textFieldExpression>
</textField>
<textField>
<reportElement mode="Opaque" x="100" y="0" width="60" height="20">
<propertyExpression name="net.sf.jasperreports.style.forecolor"><![CDATA[$F{color1}]]></propertyExpression>
<propertyExpression name="net.sf.jasperreports.style.backcolor"><![CDATA[$F{duration_color}]]></propertyExpression>
</reportElement>
<textElement textAlignment="Center" verticalAlignment="Middle"/>
<textFieldExpression><![CDATA[$F{team1}]]></textFieldExpression>
</textField>
<staticText>
<reportElement mode="Opaque" x="160" y="0" width="30" height="20">
<propertyExpression name="net.sf.jasperreports.style.backcolor"><![CDATA[$F{duration_color}]]></propertyExpression>
</reportElement>
<textElement textAlignment="Center" verticalAlignment="Middle"/>
<text><![CDATA[vs]]></text>
</staticText>
<textField>
<reportElement mode="Opaque" x="190" y="0" width="60" height="20">
<propertyExpression name="net.sf.jasperreports.style.forecolor"><![CDATA[$F{color2}]]></propertyExpression>
<propertyExpression name="net.sf.jasperreports.style.backcolor"><![CDATA[$F{duration_color}]]></propertyExpression>
</reportElement>
<textElement textAlignment="Center" verticalAlignment="Middle"/>
<textFieldExpression><![CDATA[$F{team2}]]></textFieldExpression>
</textField>
</frame>
</band>
</detail>
<summary>
<band height="50">
<staticText>
<reportElement mode="Opaque" x="20" y="0" width="100" height="20" backcolor="#F2F3F4"/>
<text><![CDATA[Extra time]]></text>
</staticText>
<staticText>
<reportElement mode="Opaque" x="20" y="20" width="100" height="20" backcolor="#F6DDCC"/>
<text><![CDATA[Penalty shootout]]></text>
</staticText>
</band>
</summary>
</jasperReport>
The frame even can be removed.
Working example. The output result
The result generated at JSS is absolutely the same:
Thanks you Alex K.
The first option of using conditional formatting was not going to work as the users can pick a large number of colours
The second option of applying the net.sf.jasperreports.style.backcolor attribute to all elements was where I was thinking of heading, but with 2 details lines with 12+ elements in each was going to be time consuming.
Instead I added a textbox element the same size as the frame, as the first element in the frame and applied the net.sf.jasperreports.style.backcolor attribute to it. I used a printWhenExpression as the colouring was only required for special make and therefore retained alternate row highlighting for the other rows in the report
<frame>
<reportElement style="Row" stretchType="ContainerHeight" mode="Opaque" x="0" y="0" width="802" height="12" isRemoveLineWhenBlank="true" uuid="b9bde183-f2ec-4051-8c7e-22072071357d"/>
<textField isStretchWithOverflow="true" isBlankWhenNull="true">
<reportElement mode="Opaque" x="0" y="0" width="798" height="12" uuid="d110cab3-6534-4c2a-9304-74a11c2a7cb8">
<propertyExpression name="net.sf.jasperreports.style.backcolor"><![CDATA[$F{sp_colour}]]></propertyExpression>
<printWhenExpression><![CDATA["Y".equals($F{is_special_make})]]>/printWhenExpression>
</reportElement>
<textElement verticalAlignment="Middle">
<font fontName="Lucida Sans" size="6"/>
</textElement>
</textField>

Understanding Jrxml with a custom datasource

I am creating a Jasper report using a custom datasource.
I am using iReport to create the report.
Although I can see report working following various articles on web, I fail to understand how the generated Jrxml knows that it is supposed to fetch data from a custom JRDatasource ?
I can't see Jrxml pointing to my custom datasource class anywhere ???
Can someone provide more information ?
Here is the generated 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="test" pageWidth="595" pageHeight="842" columnWidth="555" leftMargin="20" rightMargin="20" topMargin="20" bottomMargin="20" uuid="a19f56bb-4764-4dad-8177-9a410a0cb69d">
<property name="com.jaspersoft.studio.data.defaultdataadapter" value="New Data Adapter "/>
<queryString>
<![CDATA[]]>
</queryString>
<field name="productCode" class="java.lang.String"/>
<field name="stockLevelStatus" class="java.lang.String">
<fieldDescription><![CDATA[stockLevelStatus]]></fieldDescription>
</field>
<background>
<band splitType="Stretch"/>
</background>
<pageHeader>
<band height="35" splitType="Stretch"/>
</pageHeader>
<detail>
<band height="125" splitType="Stretch">
<textField>
<reportElement x="10" y="60" width="100" height="30" uuid="53ec360c-996a-48eb-9777-efbb9d5fa3d7"/>
<textFieldExpression><![CDATA[$F{productCode}]]></textFieldExpression>
</textField>
<staticText>
<reportElement x="10" y="0" width="100" height="30" uuid="dc8fcc8f-6294-4d5b-97de-4b68d2e6bb8b"/>
<text><![CDATA[productCode]]></text>
</staticText>
<textField>
<reportElement x="140" y="60" width="100" height="30" uuid="5219cffe-1786-4bd8-a8af-83eebda483cf"/>
<textFieldExpression><![CDATA[$F{stockLevelStatus}]]></textFieldExpression>
</textField>
<staticText>
<reportElement x="140" y="0" width="100" height="30" uuid="27edec96-50c6-4de0-830a-9593a0da7c17"/>
<text><![CDATA[stockLevelStatus]]></text>
</staticText>
</band>
</detail>
</jasperReport>
Can someone share Jrxml with custom datasource ?
Finally after a lot of R&D, I am able to solve the problem.
Here is the ".jrxml" file which allows you to plot a table in a Jasper report where table's data comes from a custom datasource.
You can find quite a few articles on web explaining how to write a custom datasource but none of them provides an example of how to use a custom datasource in a jrxml file.
<?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="custom" language="groovy" pageWidth="595" pageHeight="420" whenNoDataType="BlankPage" columnWidth="595" leftMargin="0" rightMargin="0" topMargin="0" bottomMargin="0" scriptletClass="de.hybris.platform.cockpit.reports.scriptlets.DateTimeScriptlet" resourceBundle="localization/jasperreports">
<property name="ireport.zoom" value="1.0"/>
<property name="ireport.x" value="0"/>
<property name="ireport.y" value="0"/>
<subDataset name="custome_datasource">
<queryString>
<![CDATA[select 1 from DUAL]]>
</queryString>
<field name="productCode" class="java.lang.String"/>
<field name="stockLevelStatus" class="java.lang.String">
<fieldDescription><![CDATA[stockLevelStatus]]></fieldDescription>
</field>
</subDataset>
<queryString>
<![CDATA[select 1 from DUAL]]>
</queryString>
<title>
<band height="80" splitType="Stretch">
<staticText>
<reportElement x="10" y="0" width="500" height="30"/>
<textElement textAlignment="Center" verticalAlignment="Middle">
<font fontName="Arial" size="16" isBold="true"/>
</textElement>
<text><![CDATA[Stock Level Status Report]]></text>
</staticText>
</band>
</title>
<detail>
<band height="340" splitType="Stretch">
<componentElement>
<reportElement key="table" x="0" y="0" width="555" height="238"/>
<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="custome_datasource">
<dataSourceExpression><![CDATA[new my.dataproviders.StockLevelDataProvider()]]></dataSourceExpression>
</datasetRun>
<jr:column width="130">
<jr:columnHeader height="30" rowSpan="1">
<staticText>
<reportElement x="0" y="0" width="92" height="25" backcolor="#99CCFF"/>
<textElement textAlignment="Center" verticalAlignment="Middle">
<font fontName="Arial" size="9" isBold="true"/>
</textElement>
<text><![CDATA[ProductCode]]></text>
</staticText>
</jr:columnHeader>
<jr:detailCell height="30" rowSpan="1">
<textField>
<reportElement x="0" y="10" width="90" height="20"/>
<textElement textAlignment="Center" verticalAlignment="Middle">
<font fontName="Arial" size="9" isBold="false"/>
</textElement>
<textFieldExpression class="java.lang.String"><![CDATA[$F{productCode}]]></textFieldExpression>
</textField>
</jr:detailCell>
</jr:column>
<jr:column width="130">
<jr:columnHeader height="30" rowSpan="1">
<staticText>
<reportElement x="0" y="0" width="92" height="25" backcolor="#99CCFF"/>
<textElement textAlignment="Center" verticalAlignment="Middle">
<font fontName="Arial" size="9" isBold="true"/>
</textElement>
<text><![CDATA[StockLevel]]></text>
</staticText>
</jr:columnHeader>
<jr:detailCell height="30" rowSpan="1">
<textField>
<reportElement x="0" y="10" width="90" height="20"/>
<textElement textAlignment="Center" verticalAlignment="Middle">
<font fontName="Arial" size="9" isBold="false"/>
</textElement>
<textFieldExpression class="java.lang.String"><![CDATA[$F{stockLevelStatus}]]></textFieldExpression>
</textField>
</jr:detailCell>
</jr:column>
</jr:table>
</componentElement>
</band>
</detail>

Gap between detail and column footer bands even after setting "Float Column Footer" to true

I am creating a jasper report showing some person names. I need to show the number of persons in the list at the bottom.
The problem I am facing is I am getting a small gap between persons list and the label "Total Candidates".
For the reference, please check below image:
In the beginning, column footer was getting shown at the end of page, leaving a lot of gap. Then I found few good StackOverflow links:
1) Issue with Column footer and Summary bands
2) Jasper Reports - how to get column footer to appear directly below details band
which suggested to set "Float Column Footer" to true. After doing that, the gap reduced and my column footer is almost below the detail band. But still, as shown in the picture, there is some gap remaining, which I don't know how to remove.
Edit: Here is my jrxml file:
<?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" isFloatColumnFooter="true" uuid="b7718df8-d1d7-46e7-9a66-7d3fe24c720c">
<parameter name="ReportName" class="java.lang.String"/>
<queryString>
<![CDATA[]]>
</queryString>
<field name="firstName" class="java.lang.String">
<fieldDescription><![CDATA[firstName]]></fieldDescription>
</field>
<field name="id" class="java.lang.String">
<fieldDescription><![CDATA[id]]></fieldDescription>
</field>
<field name="lastName" class="java.lang.String">
<fieldDescription><![CDATA[lastName]]></fieldDescription>
</field>
<field name="middleName" class="java.lang.String">
<fieldDescription><![CDATA[middleName]]></fieldDescription>
</field>
<title>
<band height="42" splitType="Stretch">
<textField>
<reportElement x="0" y="0" width="555" height="42" uuid="b6eaae95-75f5-4b33-978b-8afd7f9ecfee"/>
<textElement textAlignment="Center" verticalAlignment="Middle">
<font size="20"/>
</textElement>
<textFieldExpression><![CDATA[$P{ReportName}]]></textFieldExpression>
</textField>
</band>
</title>
<columnHeader>
<band height="20" splitType="Stretch">
<staticText>
<reportElement x="0" y="0" width="32" height="20" uuid="3dfe1b88-b77c-465e-bc1d-d96223c69692"/>
<text><![CDATA[Sr. No.]]></text>
</staticText>
<staticText>
<reportElement x="32" y="0" width="188" height="20" uuid="96add808-7f90-405d-93fc-ae64596df9e3"/>
<textElement textAlignment="Center"/>
<text><![CDATA[First Name]]></text>
</staticText>
<staticText>
<reportElement x="220" y="0" width="188" height="20" uuid="dd5aa422-a23c-4a4c-a464-9e927503c342"/>
<textElement textAlignment="Center"/>
<text><![CDATA[Middle Name]]></text>
</staticText>
<staticText>
<reportElement x="408" y="0" width="147" height="20" uuid="e7894574-4f95-4a04-b54b-16f636dc453c"/>
<textElement textAlignment="Center"/>
<text><![CDATA[Last Name]]></text>
</staticText>
</band>
</columnHeader>
<detail>
<band height="20" splitType="Stretch">
<textField>
<reportElement x="0" y="0" width="32" height="20" uuid="b0a9a50f-f275-4802-ba80-04559e57c75e"/>
<textFieldExpression><![CDATA[$V{REPORT_COUNT}]]></textFieldExpression>
</textField>
<textField>
<reportElement x="32" y="0" width="188" height="20" uuid="4ea4f73b-06bb-4553-848b-eecdc6be51b2"/>
<textElement textAlignment="Center"/>
<textFieldExpression><![CDATA[$F{firstName}]]></textFieldExpression>
</textField>
<textField>
<reportElement x="220" y="0" width="188" height="20" uuid="d2ea4610-7ee7-4921-babe-6d9040592843"/>
<textElement textAlignment="Center"/>
<textFieldExpression><![CDATA[$F{middleName}]]></textFieldExpression>
</textField>
<textField>
<reportElement x="408" y="0" width="147" height="20" uuid="045272ac-1387-49c6-a4e1-237725e08269"/>
<textElement textAlignment="Center"/>
<textFieldExpression><![CDATA[$F{lastName}]]></textFieldExpression>
</textField>
</band>
</detail>
<columnFooter>
<band height="20" splitType="Stretch">
<staticText>
<reportElement x="0" y="0" width="79" height="20" uuid="5a71d074-89c3-4b70-ae90-840cb37b45e8"/>
<text><![CDATA[Total Candidates:]]></text>
</staticText>
</band>
</columnFooter>
<pageFooter>
<band height="54" splitType="Stretch"/>
</pageFooter>
<summary>
<band height="42" splitType="Stretch"/>
</summary>
</jasperReport>
Any suggestions would be really appreciated!
<summary>
<band height="0" splitType="Stretch"/>
</summary>
or remove the tag completely.

One excel Sheet for each subreport (No groups in the main report)jaspersoft iReport

This is really driving me mad.. I read everywhere but still can't understand why mine isn't working
I have a main report( a dummy query returning me only one row) and 2 subreports(each with its own header) found in two different detail band. The second subreport splits into multiple excel sheets!
The main report doesn't contain any groups.. its just a dummy query and has no links with the subreports.
This is what i did in the main report:
Add in Properties : Name="net.sf.jasperreports.export.xls.one.page.per.sheet " with Value="True"
Set Ignore Pagination="True"
Added a Line element and set the Properties Expression: Name="net.sf.jasperreports.export.xls.break.after.row" and Default Value="True"
Then for the second subreport:
Set Ignore Pagination="True"
I just want one excel sheet for each subreports. But the second subreport is being split to multiple sheets... :(
Does anybody know what's the problem...?
I also read an issue with ignore pagination and page breaks here:
http://community.jaspersoft.com/ireport-designer/issues/2575
I am using the Jaspersoft iReport Designer 5.0.1
======================================
My jrxml for the main report:
<?xml version="1.0" encoding="UTF-8"?>
<jasperReport xmlns="http://jasperreports.sourceforge.net/jasperreports" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://jasperreports.sourceforge.net/jasperreports http://jasperreports.sourceforge.net/xsd/jasperreport.xsd" name="Sample_Report28022013" language="groovy" pageWidth="595" pageHeight="842" columnWidth="555" leftMargin="20" rightMargin="20" topMargin="20" bottomMargin="20" isIgnorePagination="true" uuid="1808a381-4204-4662-9cc0-7d154bcc0890">
<property name="ireport.zoom" value="1.0"/>
<property name="ireport.x" value="0"/>
<property name="ireport.y" value="0"/>
<property name="ireport.jasperserver.reportUnit" value="/reports/Test/Subreports"/>
<property name="ireport.jasperserver.url" value="http://192.168.17.114:8080/jasperserver/services/repository"/>
<property name="net.sf.jasperreports.export.xls.one.page.per.sheet" value="True"/>
<property name="net.sf.jasperreports.export.html.remove.emtpy.space.between.rows" value="True"/>
<parameter name="SUBREPORT_DIR" class="java.lang.String" isForPrompting="false">
<defaultValueExpression><![CDATA["C:\\Documents and Settings\\TreshmaC\\Desktop\\WCHY\\JasperSoft\\"]]></defaultValueExpression>
</parameter>
<queryString>
<![CDATA[SELECT
tableliste."ident" AS tableliste_ident
FROM
"public"."tableliste" tableliste
LIMIT 1]]>
</queryString>
<field name="tableliste_ident" class="java.lang.Integer"/>
<background>
<band splitType="Stretch"/>
</background>
<title>
<band height="7" splitType="Stretch"/>
</title>
<pageHeader>
<band height="5" splitType="Stretch"/>
</pageHeader>
<columnHeader>
<band height="7" splitType="Stretch"/>
</columnHeader>
<detail>
<band height="97" splitType="Stretch">
<subreport>
<reportElement uuid="ea3a0ff6-f82f-43c0-8c7b-3d06e699f2f0" x="0" y="0" width="555" height="75"/>
<connectionExpression><![CDATA[$P{REPORT_CONNECTION}]]></connectionExpression>
<subreportExpression><![CDATA["repo:Sample_Report28022013_subreport1.jrxml"]]></subreportExpression>
</subreport>
<break>
<reportElement uuid="3568174b-2ea9-4973-8e12-adcb7f54685a" x="0" y="83" width="100" height="1"/>
</break>
</band>
<band height="94" splitType="Prevent">
<subreport>
<reportElement uuid="b6ab1daa-122a-4a4b-8f60-f9fe2ba78204" x="0" y="13" width="555" height="72">
<property name="net.sf.jasperreports.export.xls.break.before.row" value="True"/>
</reportElement>
<connectionExpression><![CDATA[$P{REPORT_CONNECTION}]]></connectionExpression>
<subreportExpression><![CDATA["repo:Sample_Report28022013_subreport2.jrxml"]]></subreportExpression>
</subreport>
</band>
</detail>
<columnFooter>
<band height="7" splitType="Stretch"/>
</columnFooter>
<pageFooter>
<band height="7" splitType="Stretch"/>
</pageFooter>
<summary>
<band height="203" splitType="Stretch">
<componentElement>
<reportElement uuid="2651da09-f5ff-45de-91cb-6d9f0a8af724" x="0" y="0" width="555" height="200"/>
<mp:map xmlns:mp="http://jasperreports.sourceforge.net/jasperreports/components" xsi:schemaLocation="http://jasperreports.sourceforge.net/jasperreports/components http://jasperreports.sourceforge.net/xsd/components.xsd">
<mp:latitudeExpression><![CDATA[37.7750f]]></mp:latitudeExpression>
<mp:longitudeExpression><![CDATA[-122.4183f]]></mp:longitudeExpression>
</mp:map>
</componentElement>
</band>
</summary>
</jasperReport>
==================================================
jrxml file for the second subreport:
<?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="Sample_Report28022013_subreport2" language="groovy" pageWidth="555" pageHeight="802" columnWidth="555" leftMargin="0" rightMargin="0" topMargin="0" bottomMargin="0" isIgnorePagination="true" uuid="5a86bc51-7425-4897-b74c-0dcf7016c666">
<property name="ireport.zoom" value="1.0"/>
<property name="ireport.x" value="0"/>
<property name="ireport.y" value="0"/>
<property name="ireport.jasperserver.reportUnit" value="/reports/Test/Subreports"/>
<property name="ireport.jasperserver.url" value="http://192.168.17.114:8080/jasperserver/services/repository"/>
<property name="net.sf.jasperreports.export.html.remove.emtpy.space.between.rows" value="True"/>
<queryString>
<![CDATA[SELECT
ad_dcr."id_client" AS ad_dcr_id_client,
ad_dcr."detail_obj_dem" AS ad_dcr_detail_obj_dem,
ad_dcr."cre_mnt_octr" AS ad_dcr_cre_mnt_octr,
ad_dcr."cre_mnt_deb" AS ad_dcr_cre_mnt_deb,
ad_cli."id_client" AS ad_cli_id_client,
ad_cli."num_port" AS ad_cli_num_port,
ad_cli."pp_prenom" AS ad_cli_pp_prenom,
ad_cli."pays" AS ad_cli_pays,
ad_cli."email" AS ad_cli_email,
ad_cli."pp_nom" AS ad_cli_pp_nom
FROM
"public"."ad_cli" ad_cli LEFT JOIN "public"."ad_dcr" ad_dcr ON ad_cli."id_client" = ad_dcr."id_client"
ORDER BY ad_cli."id_client"]]>
</queryString>
<field name="ad_dcr_id_client" class="java.lang.Integer"/>
<field name="ad_dcr_detail_obj_dem" class="java.lang.String"/>
<field name="ad_dcr_cre_mnt_octr" class="java.math.BigDecimal"/>
<field name="ad_dcr_cre_mnt_deb" class="java.math.BigDecimal"/>
<field name="ad_cli_id_client" class="java.lang.Integer"/>
<field name="ad_cli_num_port" class="java.lang.String"/>
<field name="ad_cli_pp_prenom" class="java.lang.String"/>
<field name="ad_cli_pays" class="java.lang.Integer"/>
<field name="ad_cli_email" class="java.lang.String"/>
<field name="ad_cli_pp_nom" class="java.lang.String"/>
<background>
<band splitType="Stretch"/>
</background>
<title>
<band height="23" splitType="Stretch"/>
</title>
<pageHeader>
<band height="43" splitType="Stretch">
<staticText>
<reportElement uuid="a071e7c5-1a11-497b-9eee-6b243a947965" x="378" y="0" width="177" height="39"/>
<textElement textAlignment="Right">
<font fontName="Castellar" size="26"/>
</textElement>
<text><![CDATA[DCR ]]></text>
</staticText>
</band>
</pageHeader>
<columnHeader>
<band height="22" splitType="Stretch">
<frame>
<reportElement uuid="12e8ca58-2196-4a8a-9137-c5104e63a485" mode="Opaque" x="0" y="0" width="555" height="20" backcolor="#006666"/>
</frame>
<staticText>
<reportElement uuid="a1b68cab-e347-4a8f-87f8-01064a78854f" x="12" y="0" width="100" height="20" forecolor="#FFFFFF"/>
<textElement>
<font isBold="true"/>
</textElement>
<text><![CDATA[Client ID]]></text>
</staticText>
<staticText>
<reportElement uuid="8a1870d5-2682-45a1-bf8b-31a613028daf" x="312" y="0" width="143" height="20" forecolor="#FFFFFF"/>
<textElement>
<font isBold="true"/>
</textElement>
<text><![CDATA[Achat]]></text>
</staticText>
<staticText>
<reportElement uuid="df37206c-95bf-4d03-8add-3fc7ca1d07a9" x="455" y="0" width="100" height="20" forecolor="#FFFFFF"/>
<textElement textAlignment="Center">
<font isBold="true"/>
</textElement>
<text><![CDATA[Montant]]></text>
</staticText>
<staticText>
<reportElement uuid="40e2dded-de55-4692-8e8d-2e94127dd28e" x="112" y="0" width="100" height="20" forecolor="#FFFFFF"/>
<textElement>
<font isBold="true"/>
</textElement>
<text><![CDATA[Nom]]></text>
</staticText>
<staticText>
<reportElement uuid="45abf217-95a0-4ef4-963b-45c2915e5723" x="212" y="0" width="100" height="20" forecolor="#FFFFFF"/>
<textElement>
<font isBold="true"/>
</textElement>
<text><![CDATA[Pays]]></text>
</staticText>
</band>
</columnHeader>
<detail>
<band height="26" splitType="Stretch">
<textField>
<reportElement uuid="7f43f0d2-fcc2-45b3-865e-02d643954c1c" x="12" y="0" width="100" height="20"/>
<textElement/>
<textFieldExpression><![CDATA[$F{ad_dcr_id_client}]]></textFieldExpression>
</textField>
<textField>
<reportElement uuid="c14584b6-c516-423a-ac17-bc4ffeb7d74c" x="312" y="0" width="143" height="20"/>
<textElement/>
<textFieldExpression><![CDATA[$F{ad_dcr_detail_obj_dem}]]></textFieldExpression>
</textField>
<textField pattern="#,##0.00">
<reportElement uuid="88cb8587-2e82-4ea6-9c1d-f53767ffb93c" x="455" y="0" width="100" height="20"/>
<textElement textAlignment="Center"/>
<textFieldExpression><![CDATA[$F{ad_dcr_cre_mnt_deb}]]></textFieldExpression>
</textField>
<textField>
<reportElement uuid="f4feb876-fbb5-4b7b-b9fb-f24528dfb762" x="112" y="0" width="100" height="20"/>
<textElement/>
<textFieldExpression><![CDATA[$F{ad_cli_pp_nom}]]></textFieldExpression>
</textField>
<textField>
<reportElement uuid="5fed5609-a23b-4cbe-a4b2-a0ebf36e3cd5" x="212" y="0" width="100" height="20"/>
<textElement/>
<textFieldExpression><![CDATA[$F{ad_cli_pays}]]></textFieldExpression>
</textField>
<line>
<reportElement uuid="6eb43b44-1a3f-4b05-be37-4caeb35e5feb" x="0" y="20" width="555" height="1"/>
</line>
</band>
</detail>
<columnFooter>
<band height="7" splitType="Stretch"/>
</columnFooter>
<pageFooter>
<band height="8" splitType="Stretch"/>
</pageFooter>
<summary>
<band height="7" splitType="Stretch"/>
</summary>
</jasperReport>
I think You can just set the size of a page in main and sub reports to some very large value, for example 999999 and insert "page break" from pallete between sub-reports.
This way You should get each subreport in different page, but second one should not span across multiple pages.
You don´t need to do anthing in the Main. It´s all in the subreports. For example the main:
<detail>
<band height="397">
<subreport>
<reportElement positionType="Float" x="0" y="298" width="801" height="99" uuid="61789fb8-f34c-46d4-a13e-6cfeba5567a7">
<property name="com.jaspersoft.studio.unit.height" value="pixel"/>
<connectionExpression><![CDATA[$P{REPORT_CONNECTION}]]></connectionExpression>
<subreportExpression><![CDATA["repo:"]]></subreportExpression>
</subreport>
<subreport>
<reportElement positionType="Float" x="0" y="298" width="801" height="99" uuid="61789fb8-f34c-46d4-a13e-6cfeba5567a7">
<property name="com.jaspersoft.studio.unit.height" value="pixel"/>
</reportElement>
<connectionExpression><![CDATA[$P{REPORT_CONNECTION}]]></connectionExpression>
<subreportExpression><![CDATA["repo:"]]></subreportExpression>
</subreport>
</band>
</detail>
And use in the last element you have (like a textfield) a BreakAfter:
<textField isBlankWhenNull="true">
<reportElement x="280" y="0" width="120" height="30" uuid="632a6ed9-70ce-4ecd-a3e0-aaec6af95aa9">
<property name="net.sf.jasperreports.export.xls.break.after.row" value="true"/>
<property name="net.sf.jasperreports.export.xls.sheet.name" value="Nombre y apellidos"/>
</reportElement>
<box>
<topPen lineWidth="1.0"/>
</box>
<textElement textAlignment="Center" verticalAlignment="Middle">
<font size="11" isBold="true"/>
</textElement>
<textFieldExpression><![CDATA["TOTAL"]]></textFieldExpression>
</textField>
This sould be placed at the end of your report

JasperReports' iReport - generating a grand total

I have a variable datatype set up in the group footer band that generates a subtotal for the counts in each group in my report. Works great.
I would like a grand total to generate on the last page of my report, simply summing up the subtotal values. This has been harder to figure out.
Any suggestions?
You can use two variables with different resetType - for calculating sum in group (with resetType="Group" resetGroup="groupName" calculation="Sum" properties) and for calculating total sum for whole report (with resetType="Report" calculation="Sum" properties).
The sample (jrxml file):
<?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="grand_total_sample" language="groovy" pageWidth="595" pageHeight="842" columnWidth="555" leftMargin="20" rightMargin="20" topMargin="20" bottomMargin="20" isIgnorePagination="true">
<property name="ireport.zoom" value="1.0"/>
<property name="ireport.x" value="0"/>
<property name="ireport.y" value="0"/>
<queryString>
<![CDATA[SELECT DOCUMENTID, POSITIONNO, PRODUCTID, QUANTITY FROM POSITIONS WHERE PRODUCTID < 10 AND POSITIONNO > 18 ORDER BY POSITIONNO]]>
</queryString>
<field name="DOCUMENTID" class="java.lang.Integer"/>
<field name="POSITIONNO" class="java.lang.Integer"/>
<field name="PRODUCTID" class="java.lang.Integer"/>
<field name="QUANTITY" class="java.lang.Integer"/>
<variable name="quantitySumInGroup" class="java.lang.Integer" resetType="Group" resetGroup="positionNoGroup" calculation="Sum">
<variableExpression><![CDATA[$F{QUANTITY}]]></variableExpression>
<initialValueExpression><![CDATA[0]]></initialValueExpression>
</variable>
<variable name="quantityTotalSum" class="java.lang.Integer" calculation="Sum">
<variableExpression><![CDATA[$F{QUANTITY}]]></variableExpression>
<initialValueExpression><![CDATA[0]]></initialValueExpression>
</variable>
<group name="positionNoGroup">
<groupExpression><![CDATA[$F{POSITIONNO}]]></groupExpression>
<groupHeader>
<band height="20">
<textField>
<reportElement x="0" y="0" width="400" height="20"/>
<box>
<topPen lineWidth="1.0"/>
<leftPen lineWidth="1.0"/>
<bottomPen lineWidth="1.0"/>
<rightPen lineWidth="1.0"/>
</box>
<textElement textAlignment="Center">
<font isBold="true" isItalic="true" isUnderline="false"/>
</textElement>
<textFieldExpression><![CDATA["Position no: " + $F{POSITIONNO}]]></textFieldExpression>
</textField>
</band>
</groupHeader>
<groupFooter>
<band height="20">
<textField>
<reportElement x="0" y="0" width="400" height="20"/>
<textElement>
<font isBold="false" isItalic="true" isUnderline="false"/>
</textElement>
<textFieldExpression><![CDATA["Sum in group: " + $V{quantitySumInGroup}]]></textFieldExpression>
</textField>
</band>
</groupFooter>
</group>
<detail>
<band height="20" splitType="Stretch">
<textField>
<reportElement x="0" y="0" width="100" height="20"/>
<textElement/>
<textFieldExpression><![CDATA[$F{DOCUMENTID}]]></textFieldExpression>
</textField>
<textField>
<reportElement x="100" y="0" width="100" height="20"/>
<textElement/>
<textFieldExpression><![CDATA[$F{PRODUCTID}]]></textFieldExpression>
</textField>
<textField>
<reportElement x="200" y="0" width="100" height="20"/>
<textElement/>
<textFieldExpression><![CDATA[$F{QUANTITY}]]></textFieldExpression>
</textField>
</band>
</detail>
<lastPageFooter>
<band height="20">
<textField>
<reportElement x="0" y="0" width="400" height="20"/>
<textElement>
<font isBold="true" isItalic="true" isUnderline="false"/>
</textElement>
<textFieldExpression><![CDATA["Total sum: " + $V{quantityTotalSum}]]></textFieldExpression>
</textField>
</band>
</lastPageFooter>
</jasperReport>
The result will be:
Just create a new variable and in the variable expression add up all of the subtotals using their variable name
for instance:
$V{subtotal1}+$V{subtotal2}+$V{subtotal3}
After that, throw it in the 'summary' band and in the report properties check the box that says "summary on new page". That way it'll be on the last page of your report.