Unable to print borders for empty cells in PDF via JasperReports - jasper-reports

I am constructing a 'table' by having cells next to each other and they all have borders. But I have a problem where the borders won't show if the cell for workcode text doesn't have a value.
This is my jrxml - (it is a subreport so I have a extra dataset there, and workcodeText is handled this way because I don't know how many workcode text nodes I will have in the xml data.)
<?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="estimate-subreport" pageWidth="555" pageHeight="802" columnWidth="555" leftMargin="0" rightMargin="0" topMargin="0" bottomMargin="0" scriptletClass="com.cybage.mo.CostCalculation" uuid="2df6e224-aab9-42e3-a97c-aa614b05982c">
<property name="ireport.zoom" value="1.5"/>
<property name="ireport.x" value="0"/>
<property name="ireport.y" value="0"/>
<style name="Normal-Text-Small" hAlign="Left" vAlign="Top" fontName="Calibri" fontSize="9" isBold="false" isItalic="false" isUnderline="false" isStrikeThrough="false">
<box leftPadding="1" rightPadding="1"/>
</style>
<style name="Normal-Text-Small-with-borders" style="Normal-Text-Small" hAlign="Left" vAlign="Top" fontName="Calibri" fontSize="9" isBold="false" isItalic="false" isUnderline="false" isStrikeThrough="false">
<box leftPadding="1" rightPadding="1">
<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>
<style name="Normal-Text-Small-bold" style="Normal-Text-Small" hAlign="Left" vAlign="Top" fontName="Calibri" fontSize="9" isBold="true" isItalic="false" isUnderline="false" isStrikeThrough="false">
<box leftPadding="1" rightPadding="1"/>
</style>
<style name="Normal-Text-Small-bold-with-borders" style="Normal-Text-Small-bold" hAlign="Left" vAlign="Top" fontName="Calibri" fontSize="9" isBold="true" isItalic="false" isUnderline="false" isStrikeThrough="false">
<box leftPadding="1" rightPadding="1">
<pen 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="WorkcodeText" uuid="3615899a-9e63-45db-a26e-d4e6d1670f84">
<queryString language="xPath">
<![CDATA[/MCSResponse/EstimateDisplayResponse/CategoryDetail/WorkcodeDetail/WorkcodeText]]>
</queryString>
<field name="WorkcodeText" class="java.lang.String">
<fieldDescription><![CDATA[child::text()]]></fieldDescription>
</field>
<field name="last_wct" class="java.lang.String">
<fieldDescription><![CDATA[../WorkcodeText[last()]]]></fieldDescription>
</field>
<field name="WorkcodeAmount" class="java.lang.String">
<fieldDescription><![CDATA[/MCSResponse/EstimateDisplayResponse/CategoryDetail/WorkcodeDetail/WorkcodeAmount]]></fieldDescription>
</field>
<variable name="varWorkcodeText" class="java.lang.String">
<variableExpression><![CDATA[$V{varWorkcodeText}+($F{WorkcodeText} != null? $F{WorkcodeText}:" test ")]]></variableExpression>
<initialValueExpression><![CDATA[""]]></initialValueExpression>
</variable>
</subDataset>
<parameter name="SUBREPORT_DIR" class="java.lang.String" isForPrompting="false">
<defaultValueExpression><![CDATA["D:\\iReport\\Saquib\\Single_Estimate_Report\\Test\\"]]></defaultValueExpression>
</parameter>
<queryString language="xPath">
<![CDATA[CategoryDetail/WorkcodeDetail]]>
</queryString>
<field name="Workcode" class="java.lang.String">
<fieldDescription><![CDATA[Workcode]]></fieldDescription>
</field>
<field name="WorkcodeName" class="java.lang.String">
<fieldDescription><![CDATA[WorkcodeName]]></fieldDescription>
</field>
<field name="ExtraWorkcodeName" class="java.lang.String">
<fieldDescription><![CDATA[ExtraWorkcodeName]]></fieldDescription>
</field>
<field name="WorkcodeAmount" class="java.lang.String">
<fieldDescription><![CDATA[WorkcodeAmount]]></fieldDescription>
</field>
<field name="WorkcodeText" class="java.lang.String">
<fieldDescription><![CDATA[WorkcodeText]]></fieldDescription>
</field>
<field name="ItemDetail" class="java.lang.String">
<fieldDescription><![CDATA[ItemDetail]]></fieldDescription>
</field>
<detail>
<band height="15">
<componentElement>
<reportElement positionType="Float" stretchType="RelativeToTallestObject" x="150" y="0" width="300" height="15" isRemoveLineWhenBlank="true" isPrintWhenDetailOverflows="true" uuid="6b4ddd03-9978-4f83-a247-3fff22149cb1"/>
<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="WorkcodeText" uuid="7aeae23c-e1fe-4470-9ee5-98f84cd82159">
<dataSourceExpression><![CDATA[((net.sf.jasperreports.engine.data.JRXmlDataSource)$P{REPORT_DATA_SOURCE}).subDataSource("//WorkcodeText")]]></dataSourceExpression>
</datasetRun>
<jr:listContents height="15" width="300">
<textField isStretchWithOverflow="true" isBlankWhenNull="true">
<reportElement style="Normal-Text-Small-with-borders" positionType="Float" stretchType="RelativeToTallestObject" mode="Transparent" x="0" y="0" width="300" height="15" isRemoveLineWhenBlank="true" isPrintWhenDetailOverflows="true" forecolor="#0000FF" uuid="03dd8f13-7604-41be-9155-ae02aa44500e">
<printWhenExpression><![CDATA[$F{WorkcodeText}.equals($F{last_wct})]]></printWhenExpression>
</reportElement>
<textElement verticalAlignment="Top">
<font size="9"/>
</textElement>
<textFieldExpression><![CDATA[$V{varWorkcodeText}.replaceAll( "<nl>", "\n" )]]></textFieldExpression>
</textField>
</jr:listContents>
</jr:list>
</componentElement>
<textField isStretchWithOverflow="true" isBlankWhenNull="false">
<reportElement style="Normal-Text-Small-with-borders" stretchType="RelativeToTallestObject" x="0" y="0" width="20" height="15" isRemoveLineWhenBlank="true" isPrintInFirstWholeBand="true" isPrintWhenDetailOverflows="true" forecolor="#3333FF" uuid="8c9080c7-cb77-430c-be2e-b6252f9b8d8e"/>
<textElement verticalAlignment="Top">
<font size="9"/>
</textElement>
<textFieldExpression><![CDATA[$F{Workcode}]]></textFieldExpression>
</textField>
<textField isStretchWithOverflow="true" pattern="#,##0.00" isBlankWhenNull="true">
<reportElement style="Normal-Text-Small-with-borders" stretchType="RelativeToTallestObject" x="450" y="0" width="105" height="15" isRemoveLineWhenBlank="true" isPrintInFirstWholeBand="true" isPrintWhenDetailOverflows="true" forecolor="#3300FF" uuid="ebdd4d26-bc29-4546-a9b5-24f2be132aa8"/>
<textElement textAlignment="Right">
<font size="9"/>
<paragraph lineSpacing="Single"/>
</textElement>
<textFieldExpression><![CDATA[($F{WorkcodeAmount}==""||$F{WorkcodeAmount}==null)?0.00:Float.valueOf($F{WorkcodeAmount})/100]]></textFieldExpression>
</textField>
<textField isStretchWithOverflow="true" isBlankWhenNull="false">
<reportElement style="Normal-Text-Small-with-borders" stretchType="RelativeToTallestObject" x="20" y="0" width="130" height="15" isRemoveLineWhenBlank="true" isPrintInFirstWholeBand="true" isPrintWhenDetailOverflows="true" forecolor="#3333FF" uuid="f5fcc495-f401-4498-ac71-7352581cde59"/>
<textElement verticalAlignment="Top">
<font size="9"/>
<paragraph lineSpacing="Single"/>
</textElement>
<textFieldExpression><![CDATA[$F{WorkcodeName}]]></textFieldExpression>
</textField>
</band>
</detail>
This is the XML I am testing with:
<?xml version="1.0" encoding="UTF-8"?>
<CategoryDetail>
<CategoryCode>1</CategoryCode>
<CategoryName>EXTERNAL CREATIVE</CategoryName>
<CategoryTotalName>TOTAL EXTERNAL CREAT</CategoryTotalName>
<CategoryType>1</CategoryType>
<CategoryStatus>YNNYN</CategoryStatus>
<WorkcodeDetail>
<WorkcodeCategory>1</WorkcodeCategory>
<Workcode>1B</Workcode>
<WorkcodeName>VISUALS</WorkcodeName>
<WorkcodeCommissionRate>150000</WorkcodeCommissionRate>
<WorkcodeFlags>NNNNNNNN</WorkcodeFlags>
<ExtraWorkcodeName>Concept and Development</ExtraWorkcodeName>
<WorkcodeType>C</WorkcodeType>
<WorkcodeEstimateCheck>Y</WorkcodeEstimateCheck>
</WorkcodeDetail>
<WorkcodeDetail>
<WorkcodeCategory>1</WorkcodeCategory>
<Workcode>1C</Workcode>
<WorkcodeName>COPY WRITING</WorkcodeName>
<WorkcodeCommissionRate>150000</WorkcodeCommissionRate>
<WorkcodeFlags>NNNNNNNN</WorkcodeFlags>
<ExtraWorkcodeName>Visualisation/Finished Art/Lasers</ExtraWorkcodeName>
<WorkcodeType>C</WorkcodeType>
<WorkcodeEstimateCheck>Y</WorkcodeEstimateCheck>
</WorkcodeDetail>
<WorkcodeDetail>
<WorkcodeCategory>1</WorkcodeCategory>
<Workcode>1E</Workcode>
<WorkcodeName>PHOTOGRAPHY</WorkcodeName>
<WorkcodeAmount>500</WorkcodeAmount>
<WorkcodeCommissionAmount>75</WorkcodeCommissionAmount>
<WorkcodeCommissionRate>150000</WorkcodeCommissionRate>
<WorkcodeFlags>NNNNNNNN</WorkcodeFlags>
<ExtraWorkcodeName>Setting</ExtraWorkcodeName>
<WorkcodeType>C</WorkcodeType>
<WorkcodeEstimateCheck>Y</WorkcodeEstimateCheck>
<WorkcodeText>Jaspersoft was originally called Panscopic, and was founded by Al Campa, CEO, and Raj Bhargava, VP of Products in 2001. Panscopic raised $23M from Doll Capital, Discovery Ventures, Morgenthaler Ventures, and Partech. In 2004 Panscopic teamed up with</WorkcodeText>
<WorkcodeText> Teodor Danciu,[7] acquired the intellectual property of JasperReports, and changed the name of the company to Jaspersoft. Brian Gentile became CEO in 2007.<nl><nl>Jaspersoft provides commercial software around the JasperReports product, and negotiat</WorkcodeText>
<WorkcodeText>e contracts with software developers that wish to embed the JasperReports engine into a closed source product.<nl><nl>Jaspersoft's main related product is JasperReports Server, a Java EE web application that provides advanced report server capabiliti</WorkcodeText>
<WorkcodeText>es such as report scheduling and permissions. It is available under an open source license for use in conjunction with open source infrastructure such as MySQL and JBoss, or a commercial license for enterprise deployments involving commercial databas</WorkcodeText>
<WorkcodeText>es and application servers.</WorkcodeText>
</WorkcodeDetail>
<WorkcodeDetail>
<WorkcodeCategory>1</WorkcodeCategory>
<Workcode>1F</Workcode>
<WorkcodeName>ILLUSTRATIONS</WorkcodeName>
<WorkcodeCommissionRate>150000</WorkcodeCommissionRate>
<WorkcodeFlags>NNNNNNNN</WorkcodeFlags>
<ExtraWorkcodeName>Photography</ExtraWorkcodeName>
<WorkcodeType>C</WorkcodeType>
<WorkcodeEstimateCheck>Y</WorkcodeEstimateCheck>
</WorkcodeDetail>
<WorkcodeDetail>
<WorkcodeCategory>1</WorkcodeCategory>
<Workcode>1G</Workcode>
<WorkcodeName>MODEL FEES</WorkcodeName>
<WorkcodeCommissionRate>150000</WorkcodeCommissionRate>
<WorkcodeFlags>NNNNNNNN</WorkcodeFlags>
<ExtraWorkcodeName>Models</ExtraWorkcodeName>
<WorkcodeType>C</WorkcodeType>
<WorkcodeEstimateCheck>Y</WorkcodeEstimateCheck>
</WorkcodeDetail>
<WorkcodeDetail>
<WorkcodeCategory>1</WorkcodeCategory>
<Workcode>T9</Workcode>
<WorkcodeName>T3 Overtime Pr.</WorkcodeName>
<WorkcodeCommissionRate>150000</WorkcodeCommissionRate>
<WorkcodeFlags>NNNNNNNN</WorkcodeFlags>
<ExtraWorkcodeName>T3 Overtime Pr.</ExtraWorkcodeName>
<WorkcodeType>T</WorkcodeType>
<WorkcodeEstimateCheck>Y</WorkcodeEstimateCheck>
</WorkcodeDetail>
</CategoryDetail>

try isRemoveLineWhenBlank="true" set to false in your textFields

Related

Jasper Report Crosstab with ArrayList of Data

I am trying to create Jasper Report with crosstab by writing JRXML with DTOs.
I am trying to create rows dynamic number of chargeCodes and their total. It looks something like this:
jobNo
chargeCodeA
chargeCodeB
Total
jobNoABC
100.10
300.30
400.40
jobNoDEF
200.20
400.40
600.60
In my Java backend, I have DTO which looks like this
class MyDTO {
private String jobNo;
private List <String> chargeCode = new ArrayList <> ();
private List <BigDecimal> chargeCodeTotal = new ArrayList <> ();
}
where the list codeCode contains chargeCodeA, chargeCodeB for jobNoABC
and chargeCodeTotal contains 100.10, 300.30 for jobNoABC also.
In my JRXML, I have this:
<?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="vendorBillingCompletedJobReport" leftMargin="5" rightMargin="5">
<parameter name="lblJobNo" class="java.lang.String" isForPrompting="false"/>
<field name="jobNo" class="java.lang.String"/>
<field name="chargeCode" class="java.util.List"/>
<field name="chargeCodeTotal" class="java.util.List"/>
<summary>
<band height="60">
<crosstab>
<reportElement width="782" y="0" x="0" height="60" />
<rowGroup name="jobNo" width="100" totalPosition="End">
<bucket>
<bucketExpression class="java.util.List">
<![CDATA[$F{jobNo}]]>
</bucketExpression>
</bucket>
<crosstabRowHeader>
<cellContents>
<box>
<pen lineColor="black" lineWidth="1"/>
</box>
<textField>
<reportElement width="100" y="0" x="0" height="20" />
<textElement textAlignment="Right" verticalAlignment="Middle" />
<textFieldExpression>
<![CDATA[$V{jobNo}]]>
</textFieldExpression>
</textField>
</cellContents>
</crosstabRowHeader>
<crosstabTotalRowHeader>
<cellContents>
<box>
<pen lineColor="black" lineWidth="1"/>
</box>
<staticText>
<reportElement x="0" y="0" width="60" height="20" />
<textElement verticalAlignment="Middle" />
<text>TOTAL</text>
</staticText>
</cellContents>
</crosstabTotalRowHeader>
</rowGroup>
<columnGroup name="chargeCode" height="20" totalPosition="End">
<bucket>
<bucketExpression class="java.util.List">
$F{chargeCode}
</bucketExpression>
</bucket>
<crosstabColumnHeader>
<cellContents>
<box>
<pen lineColor="black" lineWidth="1"/>
</box>
<textField isStretchWithOverflow="true">
<reportElement width="60" y="0" x="0" height="20" />
<textElement verticalAlignment="Bottom" />
<textFieldExpression>
<![CDATA[$V{chargeCode}]]>
</textFieldExpression>
</textField>
</cellContents>
</crosstabColumnHeader>
<crosstabTotalColumnHeader>
<cellContents>
<box>
<pen lineColor="black" lineWidth="1"/>
</box>
<staticText>
<reportElement width="60" y="0" x="0" height="20" />
<textElement verticalAlignment="Bottom" />
<text>TOTAL</text>
</staticText>
</cellContents>
</crosstabTotalColumnHeader>
</columnGroup>
<measure name="chargeCodeTotalCount" class="java.math.BigDecimal" calculation="Sum">
<measureExpression>$F{chargeCodeTotal}</measureExpression>
</measure>
<crosstabCell height="20" width="60">
<cellContents backcolor="#FFFFFF">
<box>
<pen lineColor="black" lineWidth="1"/>
</box>
<textField>
<reportElement x="5" y="0" width="55" height="20" />
<textElement textAlignment="Left" verticalAlignment="Bottom" />
<textFieldExpression class="java.math.BigDecimal">
$V{chargeCodeTotalCount}
</textFieldExpression>
</textField>
</cellContents>
</crosstabCell>
</crosstab>
</band>
</summary>
</jasperReport>
But I am getting error:
java.lang.ClassCastException: java.util.ArrayList cannot be cast to java.lang.Comparable
at org.apache.commons.collections.comparators.ComparableComparator.compare(ComparableComparator.java:91)
I am not sure how to create infinite number of chargeCodes using JRXML.
And I cannot use Dynamic Jasper. I can only think of crosstab. Please help. Thanks.

How to send data to table component using node-jasper?

I have a task to generate PDFs with nodeJS, so i am working with the node-jasper library.
I try to display a table component but when i send dataset from back-end, it keeps showing empty table.
here is my nodjs code:
const express = require('express')
const app = express()
const port = 5000
var jasper = require('node-jasper')({
path: './lib/jasperreports-6.10.0',
reports: {
hw: {
jasper: './jasperFiles/repportBI.jasper',
jrxml: './reports/repportBI.jrxml',
conn: 'in_memory_json'
}
},
});
app.get('/jasper1', (req, res) => {
var report = {
report: 'hw',
data: {
title: "My test report",
Dataset1: jasper.toJsonDataSource(
{
dados: [
{
code: 'e1',
name: 'raouf',
function: 'Developer'
},
{
code: 'e2',
name: 'djamel',
function: 'Developer'
},
{
code: 'e3',
name: 'omar',
function: 'Medecine'
}
]
},
'dados'
),
}
,
dataset: { }
}
var pdf = jasper.pdf(report);
res.set({
'Content-type': 'application/pdf',
'Content-Length': pdf.length
});
res.send(pdf)
});
app.listen(port, () => {
console.log('app is runing on port: ', port)
})
here is my jrxml file:
<?xml version="1.0" encoding="UTF-8"?>
<!-- Created with Jaspersoft Studio version 6.10.0.final using JasperReports Library version 6.10.0-unknown -->
<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="repportBI" pageWidth="595" pageHeight="842" columnWidth="555" leftMargin="20" rightMargin="20" topMargin="20" bottomMargin="20" uuid="95744304-ed70-4001-8031-6cec31c7acbf">
<property name="com.jaspersoft.studio.data.defaultdataadapter" value="One Empty Record"/>
<style name="Table 1_TH" mode="Opaque" backcolor="#F0F8FF">
<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>
<style name="Table 1_CH" mode="Opaque" backcolor="#BFE1FF">
<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>
<style name="Table 1_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="Dataset1" uuid="70370722-01b1-41a5-a681-3d6a28fa2f84">
<queryString>
<![CDATA[]]>
</queryString>
<field name="code" class="java.lang.String"/>
<field name="name" class="java.lang.String"/>
<field name="function" class="java.lang.String"/>
</subDataset>
<parameter name="title" class="java.lang.String"/>
<parameter name="datasetTable1" class="net.sf.jasperreports.engine.data.JRBeanCollectionDataSource"/>
<queryString>
<![CDATA[]]>
</queryString>
<field name="code" class="java.lang.String"/>
<field name="name" class="java.lang.String"/>
<field name="function" class="java.lang.String"/>
<background>
<band splitType="Stretch"/>
</background>
<title>
<band height="90" splitType="Stretch">
<textField>
<reportElement x="204" y="6" width="147" height="60" uuid="4fc37721-d03e-4f94-9df8-355d2c2ed4e3"/>
<textElement textAlignment="Center">
<font size="26" isBold="true"/>
</textElement>
<textFieldExpression><![CDATA[$P{title}]]></textFieldExpression>
</textField>
</band>
</title>
<pageHeader>
<band height="35" splitType="Stretch"/>
</pageHeader>
<columnHeader>
<band height="61" splitType="Stretch"/>
</columnHeader>
<detail>
<band height="354" splitType="Stretch">
<componentElement>
<reportElement x="72" y="154" width="200" height="200" uuid="99067366-d9e3-48e1-95b3-a4d8c1e8a1db">
<property name="com.jaspersoft.studio.layout" value="com.jaspersoft.studio.editor.layout.VerticalRowLayout"/>
<property name="com.jaspersoft.studio.table.style.table_header" value="Table 1_TH"/>
<property name="com.jaspersoft.studio.table.style.column_header" value="Table 1_CH"/>
<property name="com.jaspersoft.studio.table.style.detail" value="Table 1_TD"/>
</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" whenNoDataType="AllSectionsNoDetail">
<datasetRun subDataset="Dataset1" uuid="7f03ad97-fa43-4b82-94c5-19a674ac7d7e">
<dataSourceExpression><![CDATA[$P{datasetTable1}]]></dataSourceExpression>
</datasetRun>
<jr:column width="66" uuid="40fb6564-12c3-4174-955c-23d808832359">
<property name="com.jaspersoft.studio.components.table.model.column.name" value="Colonne1"/>
<jr:columnHeader style="Table 1_CH" height="30">
<staticText>
<reportElement x="0" y="0" width="66" height="30" uuid="a6e64620-475b-4cd5-a3f6-d7dd711b2ee2"/>
<text><![CDATA[code]]></text>
</staticText>
</jr:columnHeader>
<jr:detailCell style="Table 1_TD" height="30">
<textField>
<reportElement x="0" y="0" width="66" height="30" uuid="a7d15e3a-2452-4f80-8c20-7fbcc8181fe0"/>
<textFieldExpression><![CDATA[$F{code}]]></textFieldExpression>
</textField>
</jr:detailCell>
</jr:column>
<jr:column width="66" uuid="ba0efa7e-7795-4fd2-9b71-b39f9fdcb466">
<property name="com.jaspersoft.studio.components.table.model.column.name" value="Colonne2"/>
<jr:columnHeader style="Table 1_CH" height="30">
<staticText>
<reportElement x="0" y="0" width="66" height="30" uuid="a694b15b-401f-4e8d-a726-ac8e6ddcaf05"/>
<text><![CDATA[name]]></text>
</staticText>
</jr:columnHeader>
<jr:detailCell style="Table 1_TD" height="30">
<textField>
<reportElement x="0" y="0" width="66" height="30" uuid="b0fe47b1-8a5c-4df3-8851-6e89da8bfc3a"/>
<textFieldExpression><![CDATA[$F{name}]]></textFieldExpression>
</textField>
</jr:detailCell>
</jr:column>
<jr:column width="66" uuid="d0dc532f-c2e6-4ff4-8b3e-7a8c8ab0a748">
<property name="com.jaspersoft.studio.components.table.model.column.name" value="Colonne3"/>
<jr:columnHeader style="Table 1_CH" height="30">
<staticText>
<reportElement x="0" y="0" width="66" height="30" uuid="32797f1c-a862-4e5f-b624-e1f19af58277"/>
<text><![CDATA[function]]></text>
</staticText>
</jr:columnHeader>
<jr:detailCell style="Table 1_TD" height="30">
<textField>
<reportElement x="0" y="0" width="66" height="30" uuid="ba092f73-109d-4160-b7dc-c664e83366c4"/>
<textFieldExpression><![CDATA[$F{function}]]></textFieldExpression>
</textField>
</jr:detailCell>
</jr:column>
</jr:table>
</componentElement>
</band>
</detail>
<columnFooter>
<band height="45" splitType="Stretch"/>
</columnFooter>
<pageFooter>
<band height="54" splitType="Stretch"/>
</pageFooter>
<summary>
<band height="42" splitType="Stretch"/>
</summary>
</jasperReport>
the generated PDF:
enter image description here
i can't find where the problem is, can you help me please ?
There are two problems here.
The first is that the name of the parameter in report.data (namely Dataset1) doesn't match the name of the parameter in the report (which is datasetTable1). So you'll need this in the JavaScript code:
var report = {
report: 'hw',
data: {
title: "My test report",
datasetTable1: jasper.toJsonDataSource(
...
Then, the type of the datasetTable1 parameter in the report is net.sf.jasperreports.engine.data.JRBeanCollectionDataSource, while jasper.toJsonDataSource produces a net.sf.jasperreports.engine.data.JsonDataSource object. You need to set the parameter type to JsonDataSource or to a more generic type like this:
<parameter name="datasetTable1" class="net.sf.jasperreports.engine.JRDataSource"/>

Weird positioning of elements inside a Jasper Report preview

I'm using TIBCO Jaspersoft® Studio 6.8.0 and I'm having some issues positioning things. I thought that the positioning would be kinda automatic following the GUI, but apparently it doesn't work like that.
I have a SubReport (no need for the master report right now) that calls other 2 SubReports, one for a pie chart and one for a crosstab. They both working pretty fine using subdataset from an external json (local json).
The problem is that I can't position them properly: I would need the pie chart to be positioned in the top part of the page, and the crosstab immediatly below.
Here's the subreport (used as master report now). You can see I'm using a mock (xml that calls a json), I will add the json at the end of the question.
<?xml version="1.0" encoding="UTF-8"?>
<!-- Created with Jaspersoft Studio version 6.8.0.final using JasperReports Library version 6.8.0-2ed8dfabb690ff337a5797129f2cd92902b0c87b -->
<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="ReportAnomalies_subReport" language="groovy" pageWidth="595" pageHeight="842" columnWidth="555" leftMargin="20" rightMargin="20" topMargin="20" bottomMargin="20" uuid="0a8e5b1c-8d35-4290-a283-c7fb4e197131">
<property name="com.jaspersoft.studio.data.defaultdataadapter" value="report\mock\TestTemp.xml"/>
<property name="com.jaspersoft.studio.unit.pageHeight" value="pixel"/>
<property name="com.jaspersoft.studio.unit.pageWidth" value="pixel"/>
<property name="com.jaspersoft.studio.unit.topMargin" value="pixel"/>
<property name="com.jaspersoft.studio.unit.bottomMargin" value="pixel"/>
<property name="com.jaspersoft.studio.unit.leftMargin" value="pixel"/>
<property name="com.jaspersoft.studio.unit.rightMargin" value="pixel"/>
<property name="com.jaspersoft.studio.unit.columnWidth" value="pixel"/>
<property name="com.jaspersoft.studio.unit.columnSpacing" value="pixel"/>
<style name="DefaultStyle" isDefault="true" fontName="SinaFont" fontSize="8"/>
<style name="DefaultTableStyle" style="DefaultStyle">
<box>
<pen lineWidth="0.5" lineColor="#888888"/>
</box>
</style>
<style name="DefaultTableHeaderStyle" style="DefaultTableStyle" mode="Opaque" backcolor="#F0F0F0"/>
<style name="Table_H" style="DefaultTableHeaderStyle"/>
<style name="Table_T" style="DefaultTableStyle"/>
<style name="Table_D" style="DefaultTableStyle"/>
<field name="NomeAnomalia" class="java.lang.String"/>
<field name="GruppiAnomalie" class="java.lang.Integer"/>
<field name="Total" class="java.lang.String"/>
<detail>
<band height="290">
<property name="com.jaspersoft.studio.unit.height" value="px"/>
<subreport>
<reportElement key="" x="10" y="0" width="535" height="290" uuid="37faa740-d0e0-457e-bb66-a9dbfc252683"/>
<dataSourceExpression><![CDATA[((net.sf.jasperreports.engine.data.JsonDataSource)$P{REPORT_DATA_SOURCE}).subDataSource("pieChartData")]]></dataSourceExpression>
<subreportExpression><![CDATA["ReportAnomalies_pieChart.jasper"]]></subreportExpression>
</subreport>
</band>
<band height="80">
<property name="com.jaspersoft.studio.unit.height" value="px"/>
<subreport>
<reportElement key="" style="DefaultTableStyle" x="10" y="0" width="535" height="80" uuid="ca3470c0-044b-4905-9524-5c0a948961a5">
<property name="com.jaspersoft.studio.unit.x" value="px"/>
<property name="com.jaspersoft.studio.unit.y" value="px"/>
</reportElement>
<dataSourceExpression><![CDATA[((net.sf.jasperreports.engine.data.JsonDataSource)$P{REPORT_DATA_SOURCE}).subDataSource("anomalyList")]]></dataSourceExpression>
<subreportExpression><![CDATA["ReportAnomalies_crosstab.jasper"]]></subreportExpression>
</subreport>
</band>
</detail>
</jasperReport>
The pie chart subreport (I use the workaround <printWhenExpression><![CDATA[$F{print} == 1]]></printWhenExpression> because it will print the pie chart 3 times if not used)
<?xml version="1.0" encoding="UTF-8"?>
<!-- Created with Jaspersoft Studio version 6.8.0.final using JasperReports Library version 6.8.0-2ed8dfabb690ff337a5797129f2cd92902b0c87b -->
<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="ReportAnomalies_pieChart" pageWidth="595" pageHeight="842" columnWidth="555" leftMargin="20" rightMargin="20" topMargin="20" bottomMargin="20" uuid="0a8e5b1c-8d35-4290-a283-c7fb4e197131">
<property name="com.jaspersoft.studio.unit." value="pixel"/>
<style name="DefaultStyle" isDefault="true" fontName="SinaFont" fontSize="8"/>
<style name="DefaultTableStyle" style="DefaultStyle">
<box>
<pen lineWidth="0.5" lineColor="#888888"/>
</box>
</style>
<style name="DefaultTableHeaderStyle" style="DefaultTableStyle" mode="Opaque" backcolor="#F0F0F0"/>
<style name="Table_H" style="DefaultTableHeaderStyle"/>
<style name="Table_T" style="DefaultTableStyle"/>
<style name="Table_D" style="DefaultTableStyle"/>
<field name="print" class="java.lang.Integer"/>
<field name="severityName" class="java.lang.String"/>
<field name="severityValue" class="java.lang.Integer"/>
<field name="severityLabel" class="java.lang.String"/>
<detail>
<band height="285" splitType="Stretch">
<property name="com.jaspersoft.studio.unit.height" value="px"/>
<pieChart>
<chart evaluationTime="Report">
<reportElement style="DefaultTableStyle" x="40" y="0" width="420" height="280" uuid="65c16b4b-d856-4d7f-bb7b-a0c0aa0f3a3a">
<property name="com.jaspersoft.studio.unit.height" value="px"/>
<printWhenExpression><![CDATA[$F{print} == 1]]></printWhenExpression>
</reportElement>
<box>
<topPen lineWidth="0.0" lineStyle="Solid" lineColor="#000000"/>
<leftPen lineWidth="0.0" lineStyle="Solid" lineColor="#000000"/>
<bottomPen lineWidth="0.0" lineStyle="Solid" lineColor="#000000"/>
<rightPen lineWidth="0.0" lineStyle="Solid" lineColor="#000000"/>
</box>
<chartTitle/>
<chartSubtitle/>
<chartLegend/>
</chart>
<pieDataset maxCount="3">
<keyExpression><![CDATA[$F{severityName}]]></keyExpression>
<valueExpression><![CDATA[$F{severityValue}]]></valueExpression>
<labelExpression><![CDATA[$F{severityLabel}]]></labelExpression>
</pieDataset>
<piePlot>
<plot>
<seriesColor seriesOrder="0" color="#80E31E"/>
<seriesColor seriesOrder="1" color="#F09918"/>
<seriesColor seriesOrder="2" color="#DE3700"/>
</plot>
<itemLabel/>
</piePlot>
</pieChart>
</band>
</detail>
</jasperReport>
Now the crosstab subreport
<?xml version="1.0" encoding="UTF-8"?>
<!-- Created with Jaspersoft Studio version 6.8.0.final using JasperReports Library version 6.8.0-2ed8dfabb690ff337a5797129f2cd92902b0c87b -->
<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="Prova" pageWidth="595" pageHeight="842" orientation="Landscape" whenNoDataType="NoPages" columnWidth="555" leftMargin="20" rightMargin="20" topMargin="20" bottomMargin="20" isSummaryNewPage="true" isSummaryWithPageHeaderAndFooter="true" uuid="1916d28f-c2ed-4735-a541-6dfbd82fe676">
<property name="com.jaspersoft.studio.unit." value="pixel"/>
<style name="DefaultStyle" isDefault="true" fontName="SinaFont" fontSize="8"/>
<style name="DefaultTableStyle" style="DefaultStyle">
<box>
<pen lineWidth="0.5" lineColor="#888888"/>
</box>
</style>
<style name="DefaultTableHeaderStyle" style="DefaultTableStyle" mode="Opaque" backcolor="#F0F0F0"/>
<style name="Table_H" style="DefaultTableHeaderStyle"/>
<style name="Table_T" style="DefaultTableStyle"/>
<style name="Table_D" style="DefaultTableStyle"/>
<queryString>
<![CDATA[]]>
</queryString>
<field name="NomeAnomalia" class="java.lang.String"/>
<field name="Value" class="java.lang.String"/>
<field name="Code" class="java.lang.String"/>
<field name="Severity" class="java.lang.String"/>
<field name="GruppiAnomalie" class="java.lang.String"/>
<variable name="VI" class="java.lang.Float">
<variableExpression><![CDATA[Float.parseFloat($F{Value})]]></variableExpression>
</variable>
<variable name="GruppiAnomalieI" class="java.lang.Integer">
<variableExpression><![CDATA[Integer.parseInt($F{GruppiAnomalie})]]></variableExpression>
</variable>
<group name="Group1">
<groupExpression><![CDATA[$V{GruppiAnomalieI}]]></groupExpression>
<groupFooter>
<band height="80">
<crosstab columnBreakOffset="20">
<reportElement x="30" y="0" width="520" height="70" uuid="af9d4537-350c-4e0b-a338-009d92c884d5">
<property name="com.jaspersoft.studio.layout" value="com.jaspersoft.studio.editor.layout.VerticalRowLayout"/>
<property name="net.sf.jasperreports.export.headertoolbar.table.name" value=""/>
</reportElement>
<box leftPadding="3"/>
<crosstabDataset>
<dataset resetType="Group" resetGroup="Group1"/>
</crosstabDataset>
<rowGroup name="Severity1" width="30">
<bucket class="java.lang.String">
<bucketExpression><![CDATA[$F{Severity}]]></bucketExpression>
</bucket>
<crosstabRowHeader>
<cellContents mode="Opaque" style="Table_H">
<property name="com.jaspersoft.studio.unit.width" value="pixel"/>
<textField>
<reportElement x="0" y="0" width="30" height="20" uuid="683211f0-a5a5-4cb4-aadc-658e5185baca">
<property name="com.jaspersoft.studio.unit.width" value="pixel"/>
</reportElement>
<textElement textAlignment="Center" verticalAlignment="Middle">
<font size="8"/>
</textElement>
<textFieldExpression><![CDATA[$V{Severity1}.substring(4)]]></textFieldExpression>
</textField>
</cellContents>
</crosstabRowHeader>
<crosstabTotalRowHeader>
<cellContents mode="Opaque" style="Table_T">
<staticText>
<reportElement x="0" y="0" width="60" height="20" forecolor="#FFFFFF" uuid="b709de74-24d7-42d1-975c-3ff583a2f091"/>
<text><![CDATA[Totale Severity1]]></text>
</staticText>
</cellContents>
</crosstabTotalRowHeader>
</rowGroup>
<columnGroup name="Code1" height="20">
<bucket class="java.lang.String">
<bucketExpression><![CDATA[$F{Code}]]></bucketExpression>
</bucket>
<crosstabColumnHeader>
<cellContents mode="Opaque" style="Table_H">
<property name="com.jaspersoft.studio.unit.width" value="pixel"/>
<textField>
<reportElement x="0" y="0" width="25" height="20" uuid="8e897853-1771-4c8e-af55-24e5d5e3708a"/>
<textElement textAlignment="Center" verticalAlignment="Middle">
<font size="7"/>
</textElement>
<textFieldExpression><![CDATA[$V{Code1}]]></textFieldExpression>
</textField>
</cellContents>
</crosstabColumnHeader>
<crosstabTotalColumnHeader>
<cellContents mode="Opaque" style="Table_T">
<staticText>
<reportElement x="0" y="0" width="60" height="20" forecolor="#FFFFFF" uuid="0423ca98-83a4-48b4-828b-ecc91f72c6df"/>
<text><![CDATA[Totale Code1]]></text>
</staticText>
</cellContents>
</crosstabTotalColumnHeader>
</columnGroup>
<measure name="Value_MEASURE1" class="java.lang.Float" calculation="Sum">
<measureExpression><![CDATA[$V{VI}]]></measureExpression>
</measure>
<measure name="NA" class="java.lang.String">
<measureExpression><![CDATA["n/a"]]></measureExpression>
</measure>
<crosstabCell width="25" height="20">
<cellContents mode="Opaque" style="Table_D">
<property name="com.jaspersoft.studio.unit.width" value="pixel"/>
<textField pattern="#,##0.##">
<reportElement x="0" y="0" width="25" height="20" uuid="8f7c6a83-bec1-4fdd-995b-c15df0712202"/>
<textElement textAlignment="Center" verticalAlignment="Middle">
<font size="7"/>
</textElement>
<textFieldExpression><![CDATA[$V{Value_MEASURE1} == -1 ? $V{NA} : $V{Value_MEASURE1}]]></textFieldExpression>
</textField>
</cellContents>
</crosstabCell>
</crosstab>
</band>
</groupFooter>
</group>
</jasperReport>
And finally the json file, very simple
[
{
"NomeAnomalia": "MIT Impalcati,Travi,Traversi CA CAP",
"GruppiAnomalie": 201,
"Total": "6%",
"anomalyList": [
{
"GruppiAnomalie": 201,
"Code": "cacap1",
"Name": "Macchie di umidita passiva",
"Severity": "0 - Lieve",
"Value": 3.2736806021763885
},
{
"GruppiAnomalie": 201,
"Code": "cacap12",
"Name": "Macchie di umidita passiva",
"Severity": "0 - Lieve",
"Value": 1.2736806021763885
},
{
"GruppiAnomalie": 201,
"Code": "cacap16",
"Name": "Macchie di umidita passiva",
"Severity": "2 - Forte",
"Value": 0.7736806021763885
},
{
"GruppiAnomalie": 201,
"Code": "DifGen1",
"Name": "Macchie di umidita passiva",
"Severity": "1 - Media",
"Value": 1.571812154
}
],
"pieChartData": [
{"print": 1, "severityName": "Lieve", "severityValue": 25, "severityLabel": "25%"},
{"print": 0, "severityName": "Media", "severityValue": 15, "severityLabel": "15%"},
{"print": 0, "severityName": "Forte", "severityValue": 38, "severityLabel": "38%"}
]
},
{
"NomeAnomalia": "MIT Pile,Spalle,Fondazioni CLS",
"GruppiAnomalie": 202,
"Total": "6%",
"anomalyList": [
{
"GruppiAnomalie": 202,
"Code": "cacap1",
"Name": "Macchie di umidita passiva",
"Severity": "0 - Lieve",
"Value": 3.2736806021763885
},
{
"GruppiAnomalie": 202,
"Code": "cacap12",
"Name": "Macchie di umidita passiva",
"Severity": "0 - Lieve",
"Value": 1.2736806021763885
},
{
"GruppiAnomalie": 202,
"Code": "cacap16",
"Name": "Macchie di umidita passiva",
"Severity": "2 - Forte",
"Value": 0.7736806021763885
}
],
"pieChartData": [
{"print": 1, "severityName": "Lieve", "severityValue": 25, "severityLabel": "5%"},
{"print": 0, "severityName": "Media", "severityValue": 15, "severityLabel": "87%"},
{"print": 0, "severityName": "Forte", "severityValue": 38, "severityLabel": "47%"}
]
}
]
I don't think the problem is to be found in subreports...at least not in the operational part, but I still don't know why it appears like this (3 pages instead of 2 and weird positioning)...they are in order, first, second and third page
Any suggestion?
The workaround you use in the pie chart subreport is causing the empty space in the generated report.
You set the print when expression for the pie chart element. That makes the pie chart not print for the second and third records, but the detail band itself will still consume its declared height even if the chart doesn't print.
A simple way to fix this is to set the print when expression for the band instead of the chart element. That will make the whole band not printing for the second and third records.
But a more normal solution would be to place the chart element in the summary band (with no print when expression), and remove the detail band altogether.

How to to display list of values in rowgroup in a crosstab?

I'm unable to display list of values in crosstab rowgroup
I have this sample json
{
"header": {
"columnName": [
"Product Store1",
"location"
],
"values": [{
"purchase": {
"name": "bags",
"location": "MainMarket ",
"markets":["1","2","3"]
},
"weekSpend": [{
"weekStartDate": 20181105,
"spend": 100
},
{
"weekStartDate": 20181112,
"spend": 200
}
]
},
{
"purchase": {
"name": "shoes",
"location": "MainMarket ",
"markets":["a","b","c"]
},
"weekSpend": [{
"weekStartDate": 20181105,
"spend": 100
},
{
"weekStartDate": 20181112,
"spend": 200
}
]
}
]
}
i want to show the output of market as row group as list of values Following this post jasper map crosstab crosstabHeaderCell from subdataset different from crosstabdataset
I created crosstab parameter
<crosstabParameter name="listDS" class="net.sf.jasperreports.engine.data.JsonQLDataSource">
<parameterValueExpression><![CDATA[((net.sf.jasperreports.engine.data.JsonQLDataSource)$P{REPORT_DATA_SOURCE}).subDataSource("purchase.markets")]]></parameterValueExpression>
</crosstabParameter>
then referenced this list in row group like this
<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="listSubDataset" uuid="b7fb45d8-2511-483e-9967-dd7efd283a1b">
<dataSourceExpression><![CDATA[$P{listDS}]]></dataSourceExpression>
</datasetRun>
<jr:listContents height="85" width="70">
<textField>
<reportElement x="0" y="0" width="100" height="30" uuid="672350d1-e69e-4ef3-a9da-c36d66646220"/>
<textFieldExpression><![CDATA[$F{colName}]]></textFieldExpression>
</textField>
</jr:listContents>
</jr:list>
but the generated report displays market array as null
<?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="XTabReport" pageWidth="595" pageHeight="842" columnWidth="555" leftMargin="20" rightMargin="20" topMargin="20" bottomMargin="20" uuid="33c43d53-f9b3-4cc9-92b2-bedd805d66a9">
<property name="com.jaspersoft.studio.data.defaultdataadapter" value="json_crosstab/DataAdapter.xml"/>
<style name="Crosstab_CH" mode="Opaque" backcolor="#F0F8FF">
<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>
<style name="Crosstab_CG" mode="Opaque" backcolor="#BFE1FF">
<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>
<style name="Crosstab_CT" mode="Opaque" backcolor="#005FB3">
<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>
<style name="Crosstab_CD" 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="XTabDS" uuid="9911fa6c-61b7-4952-81bf-4666e3e17fcf">
<field name="weekStartDate" class="java.lang.Integer">
<property name="net.sf.jasperreports.jsonql.field.expression" value="weekStartDate"/>
</field>
<field name="spend" class="java.lang.Integer">
<property name="net.sf.jasperreports.jsonql.field.expression" value="spend"/>
</field>
<field name="name" class="java.lang.String">
<property name="net.sf.jasperreports.jsonql.field.expression" value="^{2}.purchase.name"/>
</field>
<field name="location" class="java.lang.String">
<property name="net.sf.jasperreports.jsonql.field.expression" value="^{2}.purchase.location"/>
</field>
</subDataset>
<subDataset name="listSubDataset" uuid="01e76955-f29e-4d52-991b-aa0149bfdb37">
<field name="colName" class="java.lang.String">
<property name="net.sf.jasperreports.jsonql.field.expression" value="[0]"/>
</field>
</subDataset>
<queryString language="jsonql">
<![CDATA[]]>
</queryString>
<background>
<band splitType="Stretch"/>
</background>
<title>
<band height="58">
<staticText>
<reportElement x="140" y="10" width="280" height="30" uuid="c8e3d7ad-eeb0-4cd1-8bef-88874e6921d4"/>
<textElement textAlignment="Center" verticalAlignment="Middle">
<font size="14"/>
</textElement>
<text><![CDATA[List inside Crosstab]]></text>
</staticText>
</band>
</title>
<pageHeader>
<band height="35" splitType="Stretch"/>
</pageHeader>
<columnHeader>
<band height="30" splitType="Stretch"/>
</columnHeader>
<detail>
<band height="70" splitType="Stretch">
<crosstab>
<reportElement x="0" y="0" width="560" height="70" uuid="79f2afae-ac8b-4442-ac8e-ae1b1f68109f">
<property name="com.jaspersoft.studio.layout" value="com.jaspersoft.studio.editor.layout.VerticalRowLayout"/>
<property name="com.jaspersoft.studio.crosstab.style.header" value="Crosstab_CH"/>
<property name="com.jaspersoft.studio.crosstab.style.group" value="Crosstab_CG"/>
<property name="com.jaspersoft.studio.crosstab.style.total" value="Crosstab_CT"/>
<property name="com.jaspersoft.studio.crosstab.style.detail" value="Crosstab_CD"/>
</reportElement>
<crosstabParameter name="listDS" class="net.sf.jasperreports.engine.data.JsonQLDataSource">
<parameterValueExpression><![CDATA[((net.sf.jasperreports.engine.data.JsonQLDataSource)$P{REPORT_DATA_SOURCE}).subDataSource("purchase.markets")]]></parameterValueExpression>
</crosstabParameter>
<crosstabDataset>
<dataset>
<datasetRun subDataset="XTabDS" uuid="73b2e155-5015-451a-8813-7e2ed2f731fb">
<dataSourceExpression><![CDATA[((net.sf.jasperreports.engine.data.JsonQLDataSource)$P{REPORT_DATA_SOURCE}).subDataSource("..values..weekSpend.*")]]></dataSourceExpression>
</datasetRun>
</dataset>
</crosstabDataset>
<crosstabHeaderCell>
<cellContents>
<componentElement>
<reportElement x="0" y="0" width="180" height="30" isPrintWhenDetailOverflows="true" uuid="412c6db7-0cfa-4025-80cd-8c450f9eab96">
<property name="net.sf.jasperreports.export.headertoolbar.table.name" value=""/>
</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="Horizontal">
<datasetRun subDataset="listSubDataset" uuid="a911c80f-a0b3-4395-bbd7-2c52c67585d3">
<dataSourceExpression><![CDATA[$P{listDS}]]></dataSourceExpression>
</datasetRun>
<jr:listContents height="30" width="90">
<textField>
<reportElement x="0" y="0" width="90" height="30" isPrintWhenDetailOverflows="true" uuid="168fd030-81cf-4b80-9766-6f4637c779ec"/>
<box>
<topPen lineWidth="0.5"/>
<leftPen lineWidth="0.5"/>
</box>
<textElement>
<paragraph leftIndent="3" spacingBefore="3"/>
</textElement>
<textFieldExpression><![CDATA[$F{colName}]]></textFieldExpression>
</textField>
</jr:listContents>
</jr:list>
</componentElement>
</cellContents>
</crosstabHeaderCell>
<rowGroup name="name" width="90" totalPosition="End">
<bucket class="java.lang.String">
<bucketExpression><![CDATA[$F{name}]]></bucketExpression>
</bucket>
<crosstabRowHeader>
<cellContents mode="Opaque" style="Crosstab_CH">
<textField>
<reportElement x="0" y="0" width="90" height="20" uuid="e8aa37d7-0921-40a6-8aca-1cccae61d26d"/>
<textElement>
<paragraph leftIndent="3" spacingBefore="3"/>
</textElement>
<textFieldExpression><![CDATA[$V{name}]]></textFieldExpression>
</textField>
</cellContents>
</crosstabRowHeader>
<crosstabTotalRowHeader>
<cellContents/>
</crosstabTotalRowHeader>
</rowGroup>
<rowGroup name="location" width="90" totalPosition="End">
<bucket class="java.lang.String">
<bucketExpression><![CDATA[$F{location}]]></bucketExpression>
</bucket>
<crosstabRowHeader>
<cellContents mode="Opaque" style="Crosstab_CH">
<textField>
<reportElement x="0" y="0" width="90" height="20" uuid="86107a55-79be-4170-a2ee-b2a0ae5315e2"/>
<textElement>
<paragraph leftIndent="3" spacingBefore="3"/>
</textElement>
<textFieldExpression><![CDATA[$V{location}]]></textFieldExpression>
</textField>
</cellContents>
</crosstabRowHeader>
<crosstabTotalRowHeader>
<cellContents/>
</crosstabTotalRowHeader>
</rowGroup>
<columnGroup name="weekStartDate" height="30" totalPosition="End">
<bucket class="java.lang.Integer">
<bucketExpression><![CDATA[$F{weekStartDate}]]></bucketExpression>
</bucket>
<crosstabColumnHeader>
<cellContents mode="Opaque" style="Crosstab_CH">
<textField>
<reportElement x="0" y="0" width="90" height="30" uuid="c65fb64a-d89b-4cc3-be28-d76624cb3d93"/>
<textElement>
<paragraph leftIndent="3" spacingBefore="3"/>
</textElement>
<textFieldExpression><![CDATA[$V{weekStartDate}]]></textFieldExpression>
</textField>
</cellContents>
</crosstabColumnHeader>
<crosstabTotalColumnHeader>
<cellContents/>
</crosstabTotalColumnHeader>
</columnGroup>
<measure name="spend_MEASURE" class="java.lang.Integer">
<measureExpression><![CDATA[$F{spend}]]></measureExpression>
</measure>
<crosstabCell width="90" height="20">
<cellContents mode="Opaque" style="Crosstab_CD">
<textField>
<reportElement x="0" y="0" width="90" height="20" uuid="efb4b6dd-d9d3-4520-a94e-c0010a572b29"/>
<textElement>
<paragraph leftIndent="3" spacingBefore="3"/>
</textElement>
<textFieldExpression><![CDATA[$V{spend_MEASURE}]]></textFieldExpression>
</textField>
</cellContents>
</crosstabCell>
<crosstabCell height="20" columnTotalGroup="weekStartDate">
<cellContents/>
</crosstabCell>
<crosstabCell width="90" height="0" rowTotalGroup="location">
<cellContents/>
</crosstabCell>
<crosstabCell height="0" rowTotalGroup="location" columnTotalGroup="weekStartDate">
<cellContents/>
</crosstabCell>
<crosstabCell width="90" height="20" rowTotalGroup="name">
<cellContents/>
</crosstabCell>
<crosstabCell height="20" rowTotalGroup="name" columnTotalGroup="weekStartDate">
<cellContents/>
</crosstabCell>
</crosstab>
</band>
</detail>
<columnFooter>
<band height="45" splitType="Stretch"/>
</columnFooter>
<pageFooter>
<band height="54" splitType="Stretch"/>
</pageFooter>
<summary>
<band height="42" splitType="Stretch"/>
</summary>
</jasperReport>
excepted output is
but actual output is

Why does table throws exception when contents of TextField in any of its column header cells grow larger than page height?

Jasperreports Studio throws a runtime error during preview when the contents of a table cell (Text field) is large. Important thing here is that the Text field need to have its Stretch With Overflow property set to True
Following is the exception thrown:
net.sf.jasperreports.engine.JRException: net.sf.jasperreports.engine.JRRuntimeException: Infinite loop creating new page due to column header overflow.
at com.jaspersoft.studio.editor.preview.view.control.ReportController.fillReport(ReportController.java:536)
at com.jaspersoft.studio.editor.preview.view.control.ReportController.access$17(ReportController.java:511)
at com.jaspersoft.studio.editor.preview.view.control.ReportController$1.run(ReportController.java:429)
at org.eclipse.core.internal.jobs.Worker.run(Worker.java:56)
Caused by: net.sf.jasperreports.engine.JRRuntimeException: Infinite loop creating new page due to column header overflow.
at net.sf.jasperreports.engine.fill.JRVerticalFiller.fillColumnHeader(JRVerticalFiller.java:534)
at net.sf.jasperreports.engine.fill.JRVerticalFiller.fillReport(JRVerticalFiller.java:154)
at net.sf.jasperreports.engine.fill.JRBaseFiller.fill(JRBaseFiller.java:615)
at net.sf.jasperreports.engine.fill.JRFillSubreport.fillSubreport(JRFillSubreport.java:822)
at net.sf.jasperreports.engine.fill.JRSubreportRunnable.run(JRSubreportRunnable.java:61)
at net.sf.jasperreports.engine.fill.AbstractThreadSubreportRunner.run(AbstractThreadSubreportRunner.java:221)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1149)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:624)
at java.lang.Thread.run(Thread.java:748)
This issue can be reproduced in multiple ways but I am using simplest scenario. I have attached simple jrxml file for reference. I have used a table with empty data set. I have used Text Field expression to display data. I have set isStretchWithOverflow to true.
JRXML
<?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="Table_Based" pageWidth="842" pageHeight="595" orientation="Landscape" whenNoDataType="AllSectionsNoDetail" columnWidth="802" leftMargin="20" rightMargin="20" topMargin="20" bottomMargin="20" uuid="66519d71-4f27-4833-9a1d-c9b72e811f0c">
<property name="template.engine" value="tabular_template"/>
<property name="com.jaspersoft.studio.data.sql.tables" value=""/>
<property name="com.jaspersoft.studio.data.defaultdataadapter" value="Sample DB"/>
<style name="Title" fontName="Times New Roman" fontSize="50" isBold="true"/>
<style name="SubTitle" forecolor="#736343" fontName="Arial" fontSize="18"/>
<style name="Column header" forecolor="#666666" fontName="Arial" fontSize="12" isBold="true"/>
<style name="Row" mode="Transparent">
<conditionalStyle>
<conditionExpression><![CDATA[$V{REPORT_COUNT}%2 == 0]]></conditionExpression>
<style backcolor="#E6DAC3"/>
</conditionalStyle>
</style>
<style name="Table">
<box>
<pen lineWidth="1.0" lineColor="#000000"/>
<topPen lineWidth="1.0" lineColor="#000000"/>
<leftPen lineWidth="1.0" lineColor="#000000"/>
<bottomPen lineWidth="1.0" lineColor="#000000"/>
<rightPen lineWidth="1.0" lineColor="#000000"/>
</box>
</style>
<style name="Table_TH" mode="Opaque" backcolor="#F0F8FF">
<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>
<style name="Table_CH" mode="Opaque" backcolor="#BFE1FF">
<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>
<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="tableDataset" uuid="bcc32bbf-2279-43e0-8149-66ee3e913b5e">
<property name="com.jaspersoft.studio.data.defaultdataadapter" value="Sample DB"/>
<queryString language="SQL">
<![CDATA[]]>
</queryString>
</subDataset>
<subDataset name="Dataset1" uuid="13d74fad-eb9b-446f-a81d-55b8cf6ea0db">
<queryString>
<![CDATA[]]>
</queryString>
</subDataset>
<queryString>
<![CDATA[]]>
</queryString>
<title>
<band height="113" splitType="Stretch">
<staticText>
<reportElement style="Title" x="270" y="0" width="263" height="62" uuid="a080d2ca-6207-4d8e-87c9-d3b61fb495a9"/>
<textElement verticalAlignment="Middle"/>
<text><![CDATA[Report Title]]></text>
</staticText>
<staticText>
<reportElement style="SubTitle" x="303" y="62" width="196" height="22" uuid="0d849401-f944-4163-9df0-f69408a0618a"/>
<textElement>
<font fontName="Times New Roman"/>
</textElement>
<text><![CDATA[Report SubTitle]]></text>
</staticText>
</band>
</title>
<summary>
<band height="112" splitType="Stretch">
<property name="local_mesure_unitheight" value="pixel"/>
<property name="com.jaspersoft.studio.layout" value="com.jaspersoft.studio.editor.layout.grid.JSSGridBagLayout"/>
<componentElement>
<reportElement stretchType="ContainerBottom" x="0" y="0" width="802" height="112" isPrintWhenDetailOverflows="true" uuid="f3767496-0434-4f42-862b-5839d580e423">
<property name="com.jaspersoft.studio.layout" value="com.jaspersoft.studio.editor.layout.HorizontalRowLayout"/>
<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"/>
</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" whenNoDataType="AllSectionsNoDetail">
<datasetRun subDataset="Dataset1" uuid="05c4f663-c370-4c53-b332-ae9dfb9590e0"/>
<jr:column width="170" uuid="a3e3c62f-3558-42a1-a701-ad31853970a9">
<property name="com.jaspersoft.studio.components.table.model.column.name" value="Column1"/>
<jr:tableHeader style="Table_TH" height="30" rowSpan="1">
<staticText>
<reportElement x="0" y="0" width="170" height="30" uuid="a5ddd2d9-992d-41d2-a7d0-4cc7ec29350b"/>
<textElement>
<font size="20"/>
</textElement>
<text><![CDATA[Number]]></text>
</staticText>
</jr:tableHeader>
<jr:columnHeader style="Table_CH" height="30" rowSpan="1">
<textField>
<reportElement positionType="Float" stretchType="ElementGroupHeight" x="0" y="0" width="170" height="30" uuid="b4f24d97-8dbe-42e8-81a8-34fb336eabef"/>
<textFieldExpression><![CDATA[$V{REPORT_COUNT}]]></textFieldExpression>
</textField>
</jr:columnHeader>
<jr:detailCell style="Table_TD" height="40" rowSpan="1"/>
</jr:column>
<jr:column width="173" uuid="e2eaa014-ebfd-4795-b752-476ca2fa8f0b">
<property name="com.jaspersoft.studio.components.table.model.column.name" value="Column2"/>
<jr:tableHeader style="Table_TH" height="30" rowSpan="1">
<staticText>
<reportElement x="0" y="0" width="173" height="30" uuid="b80ae7ce-3491-45cd-963d-8638f03a3891"/>
<textElement>
<font size="20"/>
</textElement>
<text><![CDATA[Text]]></text>
</staticText>
</jr:tableHeader>
<jr:columnHeader style="Table_CH" height="30" rowSpan="1">
<textField isStretchWithOverflow="true" isBlankWhenNull="true">
<reportElement positionType="Float" x="0" y="0" width="173" height="30" isPrintWhenDetailOverflows="true" uuid="a2647f94-9054-4efd-904e-0850eead4cdf"/>
<textElement>
<paragraph lineSpacing="1_1_2"/>
</textElement>
<textFieldExpression><![CDATA[UPPER("qwertyuiopasdfghjklzxcvbnm qwertyuiopasdfghjklzxcvbnm qwertyuiopasdfghjklzxcvbnm qwertyuiopasdfghjklzxcvbnm qwertyuiopasdfghjklzxcvbnm qwertyuiopasdfghjklzxcvbnm qwertyuiopasdfghjklzxcvbnm qwertyuiopasdfghjklzxcvbnm qwertyuiopasdfghjklzxcvbnm qwertyuiopasdfghjklzxcvbnm qwertyuiopasdfghjklzxcvbnm qwertyuiopasdfghjklzxcvbnm qwertyuiopasdfghjklzxcvbnm qwertyuiopasdfghjklzxcvbnm qwertyuiopasdfghjklzxcvbnm qwertyuiopasdfghjklzxcvbnm qwertyuiopasdfghjklzxcvbnm qwertyuiopasdfghjklzxcvbnm qwertyuiopasdfghjklzxcvbnm qwertyuiopasdfghjklzxcvbnm qwertyuiopasdfghjklzxcvbnm qwertyuiopasdfghjklzxcvbnm qwertyuiopasdfghjklzxcvbnm qwertyuiopasdfghjklzxcvbnm qwertyuiopasdfghjklzxcvbnm qwertyuiopasdfghjklzxcvbnm qwertyuiopasdfghjklzxcvbnm qwertyuiopasdfghjklzxcvbnm qwertyuiopasdfghjklzxcvbnm qwertyuiopasdfghjklzxcvbnm qwertyuiopasdfghjklzxcvbnm qwertyuiopasdfghjklzxcvbnm")]]></textFieldExpression>
</textField>
</jr:columnHeader>
<jr:detailCell style="Table_TD" height="40">
<property name="com.jaspersoft.studio.layout" value="com.jaspersoft.studio.editor.layout.HorizontalRowLayout"/>
</jr:detailCell>
</jr:column>
</jr:table>
</componentElement>
</band>
</summary>
In similarly scenario Jasperreports server throws a different runtime exception:
It appears to be some kind of bug. Any help would be great help.
2018-09-21 17:03:26,667 ERROR RenderViewExceptionInterceptor,http-nio-8080-exec-8:55 - Internal server error occurred. Please contact your system administrator.
java.lang.NullPointerException
at net.sf.jasperreports.components.table.util.TableUtil.getAllColumns(TableUtil.java:162)
at net.sf.jasperreports.components.headertoolbar.json.HeaderToolbarElementJsonHandler.getColumnGroupsData(HeaderToolbarElementJsonHandler.java:832)
at net.sf.jasperreports.components.headertoolbar.json.HeaderToolbarElementJsonHandler.getJsonFragment(HeaderToolbarElementJsonHandler.java:237)
at net.sf.jasperreports.engine.export.JsonExporter.exportGenericElement(JsonExporter.java:487)
You need to redesign your report.
Currently you want a column header on each page, but your column header does not fit on page, so what happens is.
Create column header (because start of table or new page)
Break to new page (since it does not fit).
Go to 1 since new page.
net.sf.jasperreports.engine.JRRuntimeException: Infinite loop creating new page due to column header overflow.
Your solution can be all from making text smaller, column larger or truncate text so that it fits in page.