Title Band auto height - jasper-reports

Depending on Parameters some text fields are not displayed in Title Band header in my report.
But Title band height is fixed. So either I have empty blank space in title band when text fields are not displayed. Or there is compilation error when I make band height smaller and those fields are displayed.
So how to make dynamic Title Band height?
<parameter name="param" class="java.lang.Boolean">
<defaultValueExpression><![CDATA[true]]></defaultValueExpression>
</parameter>
<title>
<band height="128" splitType="Stretch">
<property name="com.jaspersoft.studio.unit.height" value="px"/>
<staticText>
<reportElement x="30" y="90" width="100" height="30" uuid="4e7618ed-21d8-47d2-99fb-7b88a5b7cfce">
<printWhenExpression><![CDATA[$P{param}]]></printWhenExpression>
</reportElement>
<text><![CDATA[Static Text]]></text>
</staticText>
<textField>
<reportElement x="30" y="10" width="100" height="30" uuid="005a53c9-a02d-436f-b35d-526ccf4aace9"/>
<textFieldExpression><![CDATA["Text Field"]]></textFieldExpression>
</textField>
<textField>
<reportElement x="30" y="50" width="100" height="30" uuid="caa2031a-3b71-43a2-bb39-916599872e94"/>
<textFieldExpression><![CDATA["Text Field"]]></textFieldExpression>
</textField>
</band>
</title>
<pageHeader>
<band height="43" splitType="Stretch">
<textField>
<reportElement x="30" y="6" width="100" height="30" uuid="30652d38-43f3-4574-a743-bb6240c2cb52"/>
<textFieldExpression><![CDATA["Text Field"]]></textFieldExpression>
</textField>
</band>
</pageHeader>
In this example there is blank space when param == false.
But if I make title band height smaller there is compilation error.

You have to set isRemoveLineWhenBlank to true for the text field.
<reportElement x="30" y="90" width="100" height="30" isRemoveLineWhenBlank="true" uuid="4e7618ed-21d8-47d2-99fb-7b88a5b7cfce">

Related

How to set table column footer to the bottom of the detail band?

I'm using table in jasperreport and I need to add table column footer to the bottom just before "group footer" band like
But currently it generates table like here
as you can see a lot of spaces between the table (which in detail band) and group footer band..
<detail>
<band height="80">
<componentElement>
<reportElement key="table1" style="tableStyle" x="1" y="0" width="552" height="80" isPrintWhenDetailOverflows="true" uuid="9a24d27b-9228-4f23-8c02-628268479882">
<printWhenExpression><![CDATA[$V{REPORT_COUNT} == 1]]></printWhenExpression>
</reportElement>
<jr:table xmlns:jr="http://jasperreports.sourceforge.net/jasperreports/components" xsi:schemaLocation="http://jasperreports.sourceforge.net/jasperreports/components http://jasperreports.sourceforge.net/xsd/components.xsd" whenNoDataType="AllSectionsNoDetail">
<datasetRun subDataset="TableDataset" uuid="aad66998-86ba-485c-b8f4-3f2f6eda4796">
<dataSourceExpression><![CDATA[$P{datasourceItems}]]></dataSourceExpression>
</datasetRun>
<jr:column width="25" uuid="eb2f74b3-8006-4762-a52e-838f5e08a86f">
<jr:columnHeader height="40" rowSpan="2">
<staticText>
<reportElement style="tableProduct_CH" x="0" y="0" width="25" height="40" uuid="6ce8147d-c282-467a-b348-0d5cf3def735"/>
<textElement textAlignment="Center" verticalAlignment="Middle"/>
<text><![CDATA[No]]></text>
</staticText>
</jr:columnHeader>
<jr:columnFooter style="tableProductFooterNoLine" height="20" rowSpan="1"/>
<jr:detailCell height="20" rowSpan="1">
<textField isStretchWithOverflow="true">
<reportElement style="tableProduct_TD" x="0" y="0" width="25" height="20" uuid="fc581740-46a3-4602-b769-18beca53d355"/>
<textElement textAlignment="Center"/>
<textFieldExpression><![CDATA[$F{no}]]></textFieldExpression>
</textField>
</jr:detailCell>
</jr:column> ...
</jr:table>
</componentElement>
</band>
</detail>
AFIK: This is not possible in jasper reports version <=6.7 (current version at date of answer) using the jr:table component.
You could draw the lines in the background band and then add the footer for example in a groupFooter band, but I would instead suggest that you create a subreport to avoid problems with page break.
The subreport will mimic the table using the standard detail and columnFooter band, again you will be adding the vertical lines in the background band.
How the columnFooter will behave is define by the attribute isFloatColumnFooter hence in your case false

How to create different page footer depending on a condition?

I have a requirement to show different footer depending on a condition.
My footer consists of many static labels and theoretically I can define a 'Print When Expression' for each of the labels. But it is inconvenient.
Q: Is it possible to select a different footer depending on a condition?
If not how else can I handle such situation without having to specify the condition in many places?
The xsd allows none or maximum one pageFooter tag with a maximum of one band.
but
This is a typical example where you can use the frame component, to group your data and decide if to display it.
Example displaying different frame with text fields depending on page number
<pageFooter>
<band height="60" splitType="Stretch">
<frame>
<reportElement x="0" y="0" width="540" height="60" uuid="d0198e94-8325-4909-9804-a8d393600ec5">
<printWhenExpression><![CDATA[$V{PAGE_NUMBER}%2!=0]]></printWhenExpression>
</reportElement>
<textField>
<reportElement x="0" y="0" width="100" height="30" uuid="379e2ac0-63ea-4493-bd38-1b7ca7b35d8c"/>
<textFieldExpression><![CDATA["Text Field 1"]]></textFieldExpression>
</textField>
<textField>
<reportElement x="0" y="30" width="100" height="30" uuid="6598ba79-08b6-4997-953d-70b64f159e3b"/>
<textFieldExpression><![CDATA["Text Field 2"]]></textFieldExpression>
</textField>
</frame>
<frame>
<reportElement x="0" y="0" width="540" height="60" uuid="d0198e94-8325-4909-9804-a8d393600ec5">
<printWhenExpression><![CDATA[$V{PAGE_NUMBER}%2==0]]></printWhenExpression>
</reportElement>
<textField>
<reportElement x="0" y="0" width="100" height="30" uuid="379e2ac0-63ea-4493-bd38-1b7ca7b35d8c"/>
<textFieldExpression><![CDATA["Text Field 3"]]></textFieldExpression>
</textField>
<textField>
<reportElement x="0" y="30" width="100" height="30" uuid="6598ba79-08b6-4997-953d-70b64f159e3b"/>
<textFieldExpression><![CDATA["Text Field 4"]]></textFieldExpression>
</textField>
</frame>
</band>
</pageFooter>
add the different text of the different pageFooter's to different frame's, then set printWhenExpression on the frame component.

Why am I unable to sum up javabean subitem's value in jrtable?

I get this exception when tying to sum nested column values
net.sf.jasperreports.engine.design.JRValidationException: Report design not valid :
1. Field not found : episodeCount
2. Variable not found : episodeTotal
How would I pass the above parameter/variable(s) to the sub dataset?
My jrxml file
<subDataset name="dataset1">
<field name="orderItem" class="com.blahblah.OrderItemPDF">
<fieldDescription><![CDATA[_THIS]]></fieldDescription>
</field>
</subDataset>
<field name="orderItems" class="java.util.Collection"/>
<field name="episodeCount" class="java.lang.Integer">
<fieldDescription><![CDATA[$F{orderItem}.getEpisodeCount()]]></fieldDescription>
</field>
<variable name="episodeTotal" class="java.lang.Integer" calculation="Sum">
<variableExpression><![CDATA[$F{episodeCount}]]></variableExpression>
</variable>
<title>
<band height="113" splitType="Stretch">
</band>
</title>
<pageHeader>
<band height="360">
<componentElement>
<reportElement x="67" y="181" width="360" height="100"/>
<jr:table xmlns:jr="http://jasperreports.sourceforge.net/jasperreports/components"
xsi:schemaLocation="http://jasperreports.sourceforge.net/jasperreports/components http://jasperreports.sourceforge.net/xsd/components.xsd">
<datasetRun subDataset="dataset1">
<dataSourceExpression>
<![CDATA[new net.sf.jasperreports.engine.data.JRBeanCollectionDataSource($F{orderItems})]]></dataSourceExpression>
</datasetRun>
<jr:column width="130">
<jr:tableHeader height="30">
<staticText>
<reportElement x="0" y="0" width="130" height="20"/>
<textElement/>
<text><![CDATA[Media Families]]></text>
</staticText>
</jr:tableHeader>
<jr:detailCell height="20">
<textField>
<reportElement x="0" y="0" width="130" height="20"/>
<textElement/>
<textFieldExpression>
<![CDATA[$F{orderItem}.getMediaFamilyName()]]></textFieldExpression>
</textField>
</jr:detailCell>
</jr:column>
<jr:column width="130">
<jr:tableHeader height="30">
<staticText>
<reportElement x="0" y="0" width="130" height="20"/>
<textElement/>
<text><![CDATA[Episodes]]></text>
</staticText>
</jr:tableHeader>
<jr:detailCell height="20">
<textField>
<reportElement x="0" y="0" width="130" height="20"/>
<textElement/>
<textFieldExpression><![CDATA[$F{orderItem}.getEpisodeCount()]]></textFieldExpression>
</textField>
</jr:detailCell>
</jr:column>
<jr:column width="60">
<jr:tableHeader height="30">
<staticText>
<reportElement x="0" y="0" width="60" height="20"/>
<textElement/>
<text><![CDATA[AdUnits]]></text>
</staticText>
</jr:tableHeader>
<!--<jr:columnFooter height="20">-->
<!--<textField>-->
<!--<reportElement x="0" y="0" width="130" height="20"/>-->
<!--<textElement/>-->
<!--<textFieldExpression><![CDATA[$V{episodeTotal}]]></textFieldExpression>-->
<!--</textField>-->
<!--</jr:columnFooter>-->
<jr:detailCell height="20">
<textField>
<reportElement x="0" y="0" width="60" height="20"/>
<textElement/>
<textFieldExpression><![CDATA[$F{orderItem}.getAdUnitCount()]]></textFieldExpression>
</textField>
</jr:detailCell>
</jr:column>
</jr:table>
</componentElement>
</band>
</pageHeader>
<columnHeader>jas
</columnHeader>
<detail>
<band/>
</detail>
When using a subDataset you need to define all your fields, parameter and variables inside of the subDataset. You can not reference fields, parameters and variables that are outside.
In your example the definition of the variable inside the subDataset would be something like this
<subDataset name="dataset1">
<field name="orderItem" class="com.blahblah.OrderItemPDF">
<fieldDescription><![CDATA[_THIS]]></fieldDescription>
</field>
<variable name="episodeTotal" class="java.lang.Integer" calculation="Sum">
<variableExpression><![CDATA[$F{orderItem}.getEpisodeCount()]]></variableExpression>
</variable>
</subDataset>
The variables and parameters and resources that are defined in outside of jrxml cannot be access from Data Set or Table directly. You need to explicitly pass these as parameter to the dataset. Otherwise, it is getting Not found error.
Something similar to
Passing main parameter to sub-datasets in JasperStudio

Detail textField overlapping

I have a small detail JasperReports's report developed with iReport. I have the classic Header band and well a row with the values, but below I need to put another textField which is in fact very long up to 500 characters namely Observations. In the Detail row one field can have up to 100 characters (namely CONCEPT) which can cause textField stretch vertically this is working OK. The problem appears when the Concept textField grows vertically the Observations which is below the Detail row stays in the same positions cause both to overlap each other...
Here is some picture of the results so far.
My report has following design (view in iReport):
And the generated report look like this:
As you can see the Observations textField if overlapping the wrap line of the CONCEPTO textField.
UPDATE after following the tips from Alex K i am receving this output....
Here is the code of Detail band:
<detail>
<band height="36" splitType="Stretch">
<textField pattern="" isBlankWhenNull="true">
<reportElement x="349" y="0" width="61" height="19"/>
<textElement textAlignment="Center"/>
<textFieldExpression class="java.lang.String"><![CDATA[$F{c04}+"€"]]></textFieldExpression>
</textField>
<textField pattern="" isBlankWhenNull="true">
<reportElement x="410" y="0" width="53" height="19"/>
<textElement textAlignment="Center"/>
<textFieldExpression class="java.lang.String"><![CDATA[$F{c05}+"€"]]></textFieldExpression>
</textField>
<textField isBlankWhenNull="true">
<reportElement x="240" y="-1" width="57" height="20"/>
<textElement textAlignment="Right"/>
<textFieldExpression class="java.lang.String"><![CDATA[$F{c06}]]></textFieldExpression>
</textField>
<textField isStretchWithOverflow="true" isBlankWhenNull="true">
<reportElement x="68" y="0" width="172" height="19"/>
<textElement/>
<textFieldExpression class="java.lang.String"><![CDATA[$F{c03}]]></textFieldExpression>
</textField>
<textField pattern="" isBlankWhenNull="true">
<reportElement x="297" y="0" width="51" height="19"/>
<textElement textAlignment="Center"/>
<textFieldExpression class="java.lang.String"><![CDATA[$F{c02}]]></textFieldExpression>
</textField>
<textField isBlankWhenNull="true">
<reportElement isPrintRepeatedValues="false" x="0" y="0" width="67" height="19"/>
<textElement/>
<textFieldExpression class="java.lang.String"><![CDATA[$F{c07}]]></textFieldExpression>
</textField>
<textField pattern="" isBlankWhenNull="true">
<reportElement positionType="Float" x="1" y="18" width="554" height="18"/>
<textElement textAlignment="Left"/>
<textFieldExpression class="java.lang.String"><![CDATA[$F{c08}]]></textFieldExpression>
</textField>
</band>
</detail>
You should set isStretchWithOverflow property as true for textField with long text (contains $F{c03} field in your case) and this properties for textField in the second row (contains $F{c08} field in your sample):
positionType with Float value;
stretchType with No stretch value;
isStretchWithOverflow with true value for support long text.
The sample
The 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="overlapping_test" language="groovy" pageWidth="595" pageHeight="842" columnWidth="555" leftMargin="20" rightMargin="20" topMargin="20" bottomMargin="20">
<queryString>
<![CDATA[]]>
</queryString>
<field name="c07" class="java.lang.String"/>
<field name="c03" class="java.lang.String"/>
<field name="c02" class="java.lang.String"/>
<field name="c04" class="java.lang.String"/>
<field name="c05" class="java.lang.String"/>
<field name="c08" class="java.lang.String"/>
<columnHeader>
<band height="20" splitType="Stretch">
<staticText>
<reportElement x="0" y="0" width="92" height="20"/>
<textElement/>
<text><![CDATA[Code]]></text>
</staticText>
<staticText>
<reportElement x="92" y="0" width="92" height="20"/>
<textElement/>
<text><![CDATA[Concept]]></text>
</staticText>
<staticText>
<reportElement x="184" y="0" width="92" height="20"/>
<textElement/>
<text><![CDATA[Candidate]]></text>
</staticText>
<staticText>
<reportElement x="276" y="0" width="92" height="20"/>
<textElement/>
<text><![CDATA[Price]]></text>
</staticText>
<staticText>
<reportElement x="368" y="0" width="92" height="20"/>
<textElement/>
<text><![CDATA[Amount]]></text>
</staticText>
</band>
</columnHeader>
<detail>
<band height="40" splitType="Stretch">
<textField>
<reportElement x="0" y="0" width="92" height="20"/>
<textElement/>
<textFieldExpression><![CDATA[$F{c07}]]></textFieldExpression>
</textField>
<textField isStretchWithOverflow="true">
<reportElement x="92" y="0" width="92" height="20"/>
<textElement/>
<textFieldExpression><![CDATA[$F{c03}]]></textFieldExpression>
</textField>
<textField>
<reportElement x="184" y="0" width="92" height="20"/>
<textElement/>
<textFieldExpression><![CDATA[$F{c02}]]></textFieldExpression>
</textField>
<textField>
<reportElement x="276" y="0" width="92" height="20"/>
<textElement/>
<textFieldExpression><![CDATA[$F{c04}]]></textFieldExpression>
</textField>
<textField>
<reportElement x="368" y="0" width="92" height="20"/>
<textElement/>
<textFieldExpression><![CDATA[$F{c05}]]></textFieldExpression>
</textField>
<textField isStretchWithOverflow="true">
<reportElement positionType="Float" x="0" y="20" width="460" height="20"/>
<textElement/>
<textFieldExpression><![CDATA[$F{c08}]]></textFieldExpression>
</textField>
</band>
</detail>
</jasperReport>
The report's design in iReport:
And the result (via preview in iReport):

Jasper server subreport in detail band

I need to create subreports in detail band, i am passing same datasource of main report to subreports.
Issue i am facing as it goes in to subreport it increments the index counter which does not allow to add remaining subreport.
MainReport.jrxml
<group name="Account Summary">
<groupHeader>
<band height="100" splitType="Stretch">
<printWhenExpression><![CDATA[$F{accountSummary.hasRepots}]]></printWhenExpression>
<subreport isUsingCache="false">
<reportElement x="28" y="0" width="540" height="100" isRemoveLineWhenBlank="true"/>
<subreportParameter name="accountSummary">
<subreportParameterExpression><![CDATA[$F{accountSummary.hasRepots}]]></subreportParameterExpression>
</subreportParameter>
<dataSourceExpression><![CDATA[$P{REPORT_DATA_SOURCE}]]></dataSourceExpression>
<subreportExpression><![CDATA[$P{SUBREPORT_DIR} + "SubReport.jasper"]]></subreportExpression>
</subreport>
</band>
</groupHeader>
</group>
SubReport.jrxml
<detail>
<band height="100" splitType="Stretch">
<subreport isUsingCache="false">
<reportElement positionType="Float" x="0" y="0" width="540" height="100" isRemoveLineWhenBlank="true"/>
<dataSourceExpression><![CDATA[$P{REPORT_DATA_SOURCE}]]></dataSourceExpression>
<subreportExpression><![CDATA[$P{SUBREPORT_DIR} + $F{subreportFileName}]]></subreportExpression>
</subreport>
</band>
</detail>
Where i pass $F{subreportFileName} from my datasource for example "SubSubReport.jrxml", but it only displays first report, i guess due to my index counter runs out in my sub-sub report so my sub report detail band doesn't go for each element.
SubSubReport.jrxml
<field name="chartData.label" class="java.lang.String"/>
<field name="chartData.value" class="java.lang.Float"/>
<field name="value1" class="java.lang.String"/>
<field name="value2" class="java.lang.String"/>
<field name="value3" class="java.lang.String"/>
<pageHeader>
<band height="114" splitType="Stretch">
<staticText>
<reportElement style="lbl-light-golden" x="12" y="19" width="170" height="67"/>
<textElement>
<font size="26"/>
</textElement>
<text><![CDATA[Some Label]]></text>
</staticText>
<pieChart>
<chart evaluationTime="Band">
<reportElement x="272" y="0" width="268" height="114"/>
<chartTitle/>
<chartSubtitle/>
<chartLegend position="Left"/>
</chart>
<pieDataset>
<keyExpression><![CDATA[$F{chartData.label}]]></keyExpression>
<valueExpression><![CDATA[$F{chartData.value}]]></valueExpression>
<labelExpression><![CDATA[null]]></labelExpression>
</pieDataset>
<piePlot isShowLabels="false" isCircular="true">
<plot/>
<itemLabel/>
</piePlot>
</pieChart>
</band>
</pageHeader>
<columnHeader>
<band height="18" splitType="Stretch">
<line>
<reportElement x="0" y="1" width="540" height="1"/>
</line>
<staticText>
<reportElement style="lbl-black-table-header" x="12" y="4" width="158" height="14"/>
<textElement/>
<text><![CDATA[Header 1]]></text>
</staticText>
<staticText>
<reportElement style="lbl-black-table-header" x="205" y="4" width="199" height="14"/>
<textElement textAlignment="Right"/>
<text><![CDATA[Header 2]]></text>
</staticText>
<staticText>
<reportElement style="lbl-black-table-header" x="445" y="4" width="74" height="13"/>
<textElement textAlignment="Center"/>
<text><![CDATA[Header 3]]></text>
</staticText>
<line>
<reportElement x="0" y="17" width="540" height="1"/>
</line>
</band>
</columnHeader>
<detail>
<band height="18" splitType="Stretch">
<textField isStretchWithOverflow="true">
<reportElement positionType="Float" x="12" y="1" width="158" height="16"/>
<textElement/>
<textFieldExpression><![CDATA[$F{value1}]]></textFieldExpression>
</textField>
<textField isStretchWithOverflow="true">
<reportElement positionType="Float" x="205" y="1" width="199" height="16"/>
<textElement textAlignment="Right">
<font isStrikeThrough="false"/>
</textElement>
<textFieldExpression><![CDATA[$F{value2}]]></textFieldExpression>
</textField>
<textField isStretchWithOverflow="true">
<reportElement positionType="Float" x="445" y="1" width="74" height="16"/>
<textElement textAlignment="Right"/>
<textFieldExpression><![CDATA[$F{value3}]]></textFieldExpression>
</textField>
</band>
</detail>
Also i tried using Groups instead of detail band as follows in "SubReport.jrxml"
SubReport.jrxml
<group name="Sub report 1">
<groupHeader>
<band height="100" splitType="Stretch">
<subreport isUsingCache="false">
<reportElement positionType="Float" x="0" y="0" width="540" height="100" isRemoveLineWhenBlank="true"/>
<dataSourceExpression><![CDATA[$P{REPORT_DATA_SOURCE}]]></dataSourceExpression>
<subreportExpression><![CDATA[$P{SUBREPORT_DIR} + "SubSubReport.jasper"]]></subreportExpression>
</subreport>
</band>
</groupHeader>
</group>
<group name="Sub report 2">
<groupHeader>
<band height="200" splitType="Stretch">
<staticText>
<reportElement x="110" y="10" width="100" height="20"/>
<textElement/>
<text><![CDATA[Sub report 2]]></text>
</staticText>
<subreport isUsingCache="false">
<reportElement positionType="Float" x="0" y="40" width="540" height="100" isRemoveLineWhenBlank="true"/>
<dataSourceExpression><![CDATA[$P{REPORT_DATA_SOURCE}]]></dataSourceExpression>
<subreportExpression><![CDATA[$P{SUBREPORT_DIR} + "SubSubReport1.jasper"]]></subreportExpression>
</subreport>
</band>
</groupHeader>
</group>
It prints "Sub report 2" label but no success with printing "SubSubReport1.jasper"
What am i doing wrong any suggestions or any direction which can help.
the report data source should never be used to feed a subreport. The REPORT_DATA_SOURCE is a data source that is a consumable object.
This means that is usable for feeding a report only once. Therefore, the parameter technique is not suitable when every record of the master report has its own subreport (unless there is only one record in the master report). I think this could be the reason that you see only one.