print when expression to display Static text if there is atleast a not null field in a detail band
I want to put a printWhenExpression on a static text based on a condition which says that print the label only if there is atleast a non null textField in a particular column in detail band.
Its like print the column header only if there is a non null field in that column.
I tried putting this expression: $F{textfield} != null
, but it works only for first record, if first record has null and second record has not null value then the label will be hidden, where as we want it to be displayed.
Please reply if you need any more info.
The below 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="IdpPdfSignature1" pageWidth="296" pageHeight="300" whenNoDataType="AllSectionsNoDetail" columnWidth="296" leftMargin="0" rightMargin="0" topMargin="0" bottomMargin="0" uuid="1c6e4be1-891b-4d0e-abfd-1c17f663d5be">
<property name="ireport.scriptlethandling" value="0"/>
<property name="ireport.encoding" value="UTF-8"/>
<import value="net.sf.jasperreports.engine.*"/>
<import value="java.util.*"/>
<import value="net.sf.jasperreports.engine.data.*"/>
<parameter name="mypic" class="java.io.InputStream" isForPrompting="false"/>
<parameter name="mypic1" class="java.io.InputStream" isForPrompting="false"/>
<parameter name="mypic2" class="java.io.InputStream" isForPrompting="false"/>
<parameter name="group" class="java.lang.String" isForPrompting="false"/>
<parameter name="device" class="java.lang.String" isForPrompting="false"/>
<parameter name="timeperiod" class="java.lang.String" isForPrompting="false"/>
<parameter name="customStartDate" class="java.util.Date" isForPrompting="false"/>
<parameter name="customEndDate" class="java.util.Date" isForPrompting="false"/>
<parameter name="footer" class="java.lang.String" isForPrompting="false"/>
<field name="signatureID" class="java.lang.String">
<fieldDescription><![CDATA[signatureID]]></fieldDescription>
</field>
<field name="signatureClassification" class="java.lang.String">
<fieldDescription><![CDATA[signatureClassification]]></fieldDescription>
</field>
<field name="description" class="java.lang.String">
<fieldDescription><![CDATA[description]]></fieldDescription>
</field>
<field name="count" class="java.lang.Long">
<fieldDescription><![CDATA[count]]></fieldDescription>
</field>
<field name="formattedCount" class="java.lang.String"/>
<field name="messageType" class="java.lang.String"/>
<variable name="mypic" class="java.io.InputStream"/>
<variable name="mypic1" class="java.io.InputStream"/>
<variable name="mypic2" class="java.io.InputStream"/>
<background>
<band splitType="Stretch"/>
</background>
<title>
<band splitType="Stretch"/>
</title>
<pageHeader>
<band splitType="Stretch"/>
</pageHeader>
<columnHeader>
<band height="16" splitType="Stretch">
<staticText>
<reportElement key="staticText-2" mode="Opaque" x="0" y="0" width="160" height="16" forecolor="#000000" backcolor="#CCCCCC" uuid="967c915b-1af1-4972-805f-0e3f365ba11c">
<printWhenExpression><![CDATA[new Boolean($F{messageType}!=null)]]></printWhenExpression>
</reportElement>
<box>
<pen lineWidth="0.25" lineColor="#000000"/>
<topPen lineWidth="0.25" lineColor="#000000"/>
<leftPen lineWidth="0.25" lineColor="#000000"/>
<bottomPen lineWidth="0.25" lineColor="#000000"/>
<rightPen lineWidth="0.25" lineColor="#000000"/>
</box>
<textElement textAlignment="Center" verticalAlignment="Middle">
<font fontName="Arial" size="10" isBold="true" pdfFontName="Helvetica-Bold"/>
</textElement>
<text><![CDATA[Signature Name]]></text>
</staticText>
<staticText>
<reportElement key="staticText-3" mode="Opaque" x="210" y="0" width="86" height="16" forecolor="#000000" backcolor="#CCCCCC" uuid="a998a72e-01fa-4c27-ad7e-1e3a6c3408d2"/>
<box>
<pen lineWidth="0.25" lineColor="#000000"/>
<topPen lineWidth="0.25" lineColor="#000000"/>
<leftPen lineWidth="0.25" lineColor="#000000"/>
<bottomPen lineWidth="0.25" lineColor="#000000"/>
<rightPen lineWidth="0.25" lineColor="#000000"/>
</box>
<textElement textAlignment="Center" verticalAlignment="Middle">
<font fontName="Arial" size="10" isBold="true" pdfFontName="Helvetica-Bold"/>
</textElement>
<text><![CDATA[Event Count]]></text>
</staticText>
<staticText>
<reportElement key="staticText-11" mode="Opaque" x="160" y="0" width="50" height="16" forecolor="#000000" backcolor="#CCCCCC" uuid="5170b4a6-3531-412d-9f8f-bc32dc4de0be">
<printWhenExpression><![CDATA[new Boolean($F{messageType}!=null)]]></printWhenExpression>
</reportElement>
<box>
<pen lineWidth="0.25" lineColor="#000000"/>
<topPen lineWidth="0.25" lineColor="#000000"/>
<leftPen lineWidth="0.25" lineColor="#000000"/>
<bottomPen lineWidth="0.25" lineColor="#000000"/>
<rightPen lineWidth="0.25" lineColor="#000000"/>
</box>
<textElement textAlignment="Center" verticalAlignment="Middle">
<font fontName="Arial" size="10" isBold="true" pdfFontName="Helvetica-Bold"/>
</textElement>
<text><![CDATA[Type]]></text>
</staticText>
</band>
</columnHeader>
<detail>
<band height="16" splitType="Stretch">
<textField isStretchWithOverflow="true" isBlankWhenNull="true">
<reportElement key="textField-7" stretchType="RelativeToTallestObject" x="160" y="0" width="50" height="16" uuid="917d3aff-44a7-4a26-865a-d466aff3ab00">
<printWhenExpression><![CDATA[new Boolean($F{messageType}!=null)]]></printWhenExpression>
</reportElement>
<box leftPadding="5">
<topPen lineWidth="0.25" lineColor="#999999"/>
<leftPen lineWidth="0.25" lineColor="#999999"/>
<bottomPen lineWidth="0.25" lineColor="#999999"/>
<rightPen lineWidth="0.25" lineColor="#999999"/>
</box>
<textElement textAlignment="Left">
<font fontName="Arial"/>
</textElement>
<textFieldExpression><![CDATA[$F{messageType}]]></textFieldExpression>
</textField>
<textField isStretchWithOverflow="true" isBlankWhenNull="true">
<reportElement key="textField" stretchType="RelativeToTallestObject" x="0" y="0" width="160" height="16" uuid="72492119-a45f-49c5-8fb8-19252c57e402">
<printWhenExpression><![CDATA[new Boolean($F{messageType}!=null)]]></printWhenExpression>
</reportElement>
<box leftPadding="5" rightPadding="10">
<topPen lineWidth="0.25" lineColor="#999999"/>
<leftPen lineWidth="0.25" lineColor="#999999"/>
<bottomPen lineWidth="0.25" lineColor="#999999"/>
<rightPen lineWidth="0.25" lineColor="#999999"/>
</box>
<textElement>
<font fontName="Arial"/>
</textElement>
<textFieldExpression><![CDATA[$F{signatureClassification}]]></textFieldExpression>
</textField>
<textField isStretchWithOverflow="true" isBlankWhenNull="true">
<reportElement key="textField" stretchType="RelativeToTallestObject" x="210" y="0" width="86" height="16" uuid="223be44f-8565-40e3-9d43-0f13b4e159b7"/>
<box leftPadding="5" rightPadding="10">
<topPen lineWidth="0.25" lineColor="#999999"/>
<leftPen lineWidth="0.25" lineColor="#999999"/>
<bottomPen lineWidth="0.25" lineColor="#999999"/>
<rightPen lineWidth="0.25" lineColor="#999999"/>
</box>
<textElement textAlignment="Right">
<font fontName="Arial"/>
</textElement>
<textFieldExpression><![CDATA[$F{formattedCount}]]></textFieldExpression>
</textField>
</band>
</detail>
<columnFooter>
<band splitType="Stretch"/>
</columnFooter>
<pageFooter>
<band splitType="Stretch"/>
</pageFooter>
<summary>
<band splitType="Stretch"/>
</summary>
</jasperReport>
jasper-reports expression
add a comment |
I want to put a printWhenExpression on a static text based on a condition which says that print the label only if there is atleast a non null textField in a particular column in detail band.
Its like print the column header only if there is a non null field in that column.
I tried putting this expression: $F{textfield} != null
, but it works only for first record, if first record has null and second record has not null value then the label will be hidden, where as we want it to be displayed.
Please reply if you need any more info.
The below 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="IdpPdfSignature1" pageWidth="296" pageHeight="300" whenNoDataType="AllSectionsNoDetail" columnWidth="296" leftMargin="0" rightMargin="0" topMargin="0" bottomMargin="0" uuid="1c6e4be1-891b-4d0e-abfd-1c17f663d5be">
<property name="ireport.scriptlethandling" value="0"/>
<property name="ireport.encoding" value="UTF-8"/>
<import value="net.sf.jasperreports.engine.*"/>
<import value="java.util.*"/>
<import value="net.sf.jasperreports.engine.data.*"/>
<parameter name="mypic" class="java.io.InputStream" isForPrompting="false"/>
<parameter name="mypic1" class="java.io.InputStream" isForPrompting="false"/>
<parameter name="mypic2" class="java.io.InputStream" isForPrompting="false"/>
<parameter name="group" class="java.lang.String" isForPrompting="false"/>
<parameter name="device" class="java.lang.String" isForPrompting="false"/>
<parameter name="timeperiod" class="java.lang.String" isForPrompting="false"/>
<parameter name="customStartDate" class="java.util.Date" isForPrompting="false"/>
<parameter name="customEndDate" class="java.util.Date" isForPrompting="false"/>
<parameter name="footer" class="java.lang.String" isForPrompting="false"/>
<field name="signatureID" class="java.lang.String">
<fieldDescription><![CDATA[signatureID]]></fieldDescription>
</field>
<field name="signatureClassification" class="java.lang.String">
<fieldDescription><![CDATA[signatureClassification]]></fieldDescription>
</field>
<field name="description" class="java.lang.String">
<fieldDescription><![CDATA[description]]></fieldDescription>
</field>
<field name="count" class="java.lang.Long">
<fieldDescription><![CDATA[count]]></fieldDescription>
</field>
<field name="formattedCount" class="java.lang.String"/>
<field name="messageType" class="java.lang.String"/>
<variable name="mypic" class="java.io.InputStream"/>
<variable name="mypic1" class="java.io.InputStream"/>
<variable name="mypic2" class="java.io.InputStream"/>
<background>
<band splitType="Stretch"/>
</background>
<title>
<band splitType="Stretch"/>
</title>
<pageHeader>
<band splitType="Stretch"/>
</pageHeader>
<columnHeader>
<band height="16" splitType="Stretch">
<staticText>
<reportElement key="staticText-2" mode="Opaque" x="0" y="0" width="160" height="16" forecolor="#000000" backcolor="#CCCCCC" uuid="967c915b-1af1-4972-805f-0e3f365ba11c">
<printWhenExpression><![CDATA[new Boolean($F{messageType}!=null)]]></printWhenExpression>
</reportElement>
<box>
<pen lineWidth="0.25" lineColor="#000000"/>
<topPen lineWidth="0.25" lineColor="#000000"/>
<leftPen lineWidth="0.25" lineColor="#000000"/>
<bottomPen lineWidth="0.25" lineColor="#000000"/>
<rightPen lineWidth="0.25" lineColor="#000000"/>
</box>
<textElement textAlignment="Center" verticalAlignment="Middle">
<font fontName="Arial" size="10" isBold="true" pdfFontName="Helvetica-Bold"/>
</textElement>
<text><![CDATA[Signature Name]]></text>
</staticText>
<staticText>
<reportElement key="staticText-3" mode="Opaque" x="210" y="0" width="86" height="16" forecolor="#000000" backcolor="#CCCCCC" uuid="a998a72e-01fa-4c27-ad7e-1e3a6c3408d2"/>
<box>
<pen lineWidth="0.25" lineColor="#000000"/>
<topPen lineWidth="0.25" lineColor="#000000"/>
<leftPen lineWidth="0.25" lineColor="#000000"/>
<bottomPen lineWidth="0.25" lineColor="#000000"/>
<rightPen lineWidth="0.25" lineColor="#000000"/>
</box>
<textElement textAlignment="Center" verticalAlignment="Middle">
<font fontName="Arial" size="10" isBold="true" pdfFontName="Helvetica-Bold"/>
</textElement>
<text><![CDATA[Event Count]]></text>
</staticText>
<staticText>
<reportElement key="staticText-11" mode="Opaque" x="160" y="0" width="50" height="16" forecolor="#000000" backcolor="#CCCCCC" uuid="5170b4a6-3531-412d-9f8f-bc32dc4de0be">
<printWhenExpression><![CDATA[new Boolean($F{messageType}!=null)]]></printWhenExpression>
</reportElement>
<box>
<pen lineWidth="0.25" lineColor="#000000"/>
<topPen lineWidth="0.25" lineColor="#000000"/>
<leftPen lineWidth="0.25" lineColor="#000000"/>
<bottomPen lineWidth="0.25" lineColor="#000000"/>
<rightPen lineWidth="0.25" lineColor="#000000"/>
</box>
<textElement textAlignment="Center" verticalAlignment="Middle">
<font fontName="Arial" size="10" isBold="true" pdfFontName="Helvetica-Bold"/>
</textElement>
<text><![CDATA[Type]]></text>
</staticText>
</band>
</columnHeader>
<detail>
<band height="16" splitType="Stretch">
<textField isStretchWithOverflow="true" isBlankWhenNull="true">
<reportElement key="textField-7" stretchType="RelativeToTallestObject" x="160" y="0" width="50" height="16" uuid="917d3aff-44a7-4a26-865a-d466aff3ab00">
<printWhenExpression><![CDATA[new Boolean($F{messageType}!=null)]]></printWhenExpression>
</reportElement>
<box leftPadding="5">
<topPen lineWidth="0.25" lineColor="#999999"/>
<leftPen lineWidth="0.25" lineColor="#999999"/>
<bottomPen lineWidth="0.25" lineColor="#999999"/>
<rightPen lineWidth="0.25" lineColor="#999999"/>
</box>
<textElement textAlignment="Left">
<font fontName="Arial"/>
</textElement>
<textFieldExpression><![CDATA[$F{messageType}]]></textFieldExpression>
</textField>
<textField isStretchWithOverflow="true" isBlankWhenNull="true">
<reportElement key="textField" stretchType="RelativeToTallestObject" x="0" y="0" width="160" height="16" uuid="72492119-a45f-49c5-8fb8-19252c57e402">
<printWhenExpression><![CDATA[new Boolean($F{messageType}!=null)]]></printWhenExpression>
</reportElement>
<box leftPadding="5" rightPadding="10">
<topPen lineWidth="0.25" lineColor="#999999"/>
<leftPen lineWidth="0.25" lineColor="#999999"/>
<bottomPen lineWidth="0.25" lineColor="#999999"/>
<rightPen lineWidth="0.25" lineColor="#999999"/>
</box>
<textElement>
<font fontName="Arial"/>
</textElement>
<textFieldExpression><![CDATA[$F{signatureClassification}]]></textFieldExpression>
</textField>
<textField isStretchWithOverflow="true" isBlankWhenNull="true">
<reportElement key="textField" stretchType="RelativeToTallestObject" x="210" y="0" width="86" height="16" uuid="223be44f-8565-40e3-9d43-0f13b4e159b7"/>
<box leftPadding="5" rightPadding="10">
<topPen lineWidth="0.25" lineColor="#999999"/>
<leftPen lineWidth="0.25" lineColor="#999999"/>
<bottomPen lineWidth="0.25" lineColor="#999999"/>
<rightPen lineWidth="0.25" lineColor="#999999"/>
</box>
<textElement textAlignment="Right">
<font fontName="Arial"/>
</textElement>
<textFieldExpression><![CDATA[$F{formattedCount}]]></textFieldExpression>
</textField>
</band>
</detail>
<columnFooter>
<band splitType="Stretch"/>
</columnFooter>
<pageFooter>
<band splitType="Stretch"/>
</pageFooter>
<summary>
<band splitType="Stretch"/>
</summary>
</jasperReport>
jasper-reports expression
Possible duplicate of How to show/hide a column at runtime?
– Alex K
Jul 21 '16 at 21:11
add a comment |
I want to put a printWhenExpression on a static text based on a condition which says that print the label only if there is atleast a non null textField in a particular column in detail band.
Its like print the column header only if there is a non null field in that column.
I tried putting this expression: $F{textfield} != null
, but it works only for first record, if first record has null and second record has not null value then the label will be hidden, where as we want it to be displayed.
Please reply if you need any more info.
The below 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="IdpPdfSignature1" pageWidth="296" pageHeight="300" whenNoDataType="AllSectionsNoDetail" columnWidth="296" leftMargin="0" rightMargin="0" topMargin="0" bottomMargin="0" uuid="1c6e4be1-891b-4d0e-abfd-1c17f663d5be">
<property name="ireport.scriptlethandling" value="0"/>
<property name="ireport.encoding" value="UTF-8"/>
<import value="net.sf.jasperreports.engine.*"/>
<import value="java.util.*"/>
<import value="net.sf.jasperreports.engine.data.*"/>
<parameter name="mypic" class="java.io.InputStream" isForPrompting="false"/>
<parameter name="mypic1" class="java.io.InputStream" isForPrompting="false"/>
<parameter name="mypic2" class="java.io.InputStream" isForPrompting="false"/>
<parameter name="group" class="java.lang.String" isForPrompting="false"/>
<parameter name="device" class="java.lang.String" isForPrompting="false"/>
<parameter name="timeperiod" class="java.lang.String" isForPrompting="false"/>
<parameter name="customStartDate" class="java.util.Date" isForPrompting="false"/>
<parameter name="customEndDate" class="java.util.Date" isForPrompting="false"/>
<parameter name="footer" class="java.lang.String" isForPrompting="false"/>
<field name="signatureID" class="java.lang.String">
<fieldDescription><![CDATA[signatureID]]></fieldDescription>
</field>
<field name="signatureClassification" class="java.lang.String">
<fieldDescription><![CDATA[signatureClassification]]></fieldDescription>
</field>
<field name="description" class="java.lang.String">
<fieldDescription><![CDATA[description]]></fieldDescription>
</field>
<field name="count" class="java.lang.Long">
<fieldDescription><![CDATA[count]]></fieldDescription>
</field>
<field name="formattedCount" class="java.lang.String"/>
<field name="messageType" class="java.lang.String"/>
<variable name="mypic" class="java.io.InputStream"/>
<variable name="mypic1" class="java.io.InputStream"/>
<variable name="mypic2" class="java.io.InputStream"/>
<background>
<band splitType="Stretch"/>
</background>
<title>
<band splitType="Stretch"/>
</title>
<pageHeader>
<band splitType="Stretch"/>
</pageHeader>
<columnHeader>
<band height="16" splitType="Stretch">
<staticText>
<reportElement key="staticText-2" mode="Opaque" x="0" y="0" width="160" height="16" forecolor="#000000" backcolor="#CCCCCC" uuid="967c915b-1af1-4972-805f-0e3f365ba11c">
<printWhenExpression><![CDATA[new Boolean($F{messageType}!=null)]]></printWhenExpression>
</reportElement>
<box>
<pen lineWidth="0.25" lineColor="#000000"/>
<topPen lineWidth="0.25" lineColor="#000000"/>
<leftPen lineWidth="0.25" lineColor="#000000"/>
<bottomPen lineWidth="0.25" lineColor="#000000"/>
<rightPen lineWidth="0.25" lineColor="#000000"/>
</box>
<textElement textAlignment="Center" verticalAlignment="Middle">
<font fontName="Arial" size="10" isBold="true" pdfFontName="Helvetica-Bold"/>
</textElement>
<text><![CDATA[Signature Name]]></text>
</staticText>
<staticText>
<reportElement key="staticText-3" mode="Opaque" x="210" y="0" width="86" height="16" forecolor="#000000" backcolor="#CCCCCC" uuid="a998a72e-01fa-4c27-ad7e-1e3a6c3408d2"/>
<box>
<pen lineWidth="0.25" lineColor="#000000"/>
<topPen lineWidth="0.25" lineColor="#000000"/>
<leftPen lineWidth="0.25" lineColor="#000000"/>
<bottomPen lineWidth="0.25" lineColor="#000000"/>
<rightPen lineWidth="0.25" lineColor="#000000"/>
</box>
<textElement textAlignment="Center" verticalAlignment="Middle">
<font fontName="Arial" size="10" isBold="true" pdfFontName="Helvetica-Bold"/>
</textElement>
<text><![CDATA[Event Count]]></text>
</staticText>
<staticText>
<reportElement key="staticText-11" mode="Opaque" x="160" y="0" width="50" height="16" forecolor="#000000" backcolor="#CCCCCC" uuid="5170b4a6-3531-412d-9f8f-bc32dc4de0be">
<printWhenExpression><![CDATA[new Boolean($F{messageType}!=null)]]></printWhenExpression>
</reportElement>
<box>
<pen lineWidth="0.25" lineColor="#000000"/>
<topPen lineWidth="0.25" lineColor="#000000"/>
<leftPen lineWidth="0.25" lineColor="#000000"/>
<bottomPen lineWidth="0.25" lineColor="#000000"/>
<rightPen lineWidth="0.25" lineColor="#000000"/>
</box>
<textElement textAlignment="Center" verticalAlignment="Middle">
<font fontName="Arial" size="10" isBold="true" pdfFontName="Helvetica-Bold"/>
</textElement>
<text><![CDATA[Type]]></text>
</staticText>
</band>
</columnHeader>
<detail>
<band height="16" splitType="Stretch">
<textField isStretchWithOverflow="true" isBlankWhenNull="true">
<reportElement key="textField-7" stretchType="RelativeToTallestObject" x="160" y="0" width="50" height="16" uuid="917d3aff-44a7-4a26-865a-d466aff3ab00">
<printWhenExpression><![CDATA[new Boolean($F{messageType}!=null)]]></printWhenExpression>
</reportElement>
<box leftPadding="5">
<topPen lineWidth="0.25" lineColor="#999999"/>
<leftPen lineWidth="0.25" lineColor="#999999"/>
<bottomPen lineWidth="0.25" lineColor="#999999"/>
<rightPen lineWidth="0.25" lineColor="#999999"/>
</box>
<textElement textAlignment="Left">
<font fontName="Arial"/>
</textElement>
<textFieldExpression><![CDATA[$F{messageType}]]></textFieldExpression>
</textField>
<textField isStretchWithOverflow="true" isBlankWhenNull="true">
<reportElement key="textField" stretchType="RelativeToTallestObject" x="0" y="0" width="160" height="16" uuid="72492119-a45f-49c5-8fb8-19252c57e402">
<printWhenExpression><![CDATA[new Boolean($F{messageType}!=null)]]></printWhenExpression>
</reportElement>
<box leftPadding="5" rightPadding="10">
<topPen lineWidth="0.25" lineColor="#999999"/>
<leftPen lineWidth="0.25" lineColor="#999999"/>
<bottomPen lineWidth="0.25" lineColor="#999999"/>
<rightPen lineWidth="0.25" lineColor="#999999"/>
</box>
<textElement>
<font fontName="Arial"/>
</textElement>
<textFieldExpression><![CDATA[$F{signatureClassification}]]></textFieldExpression>
</textField>
<textField isStretchWithOverflow="true" isBlankWhenNull="true">
<reportElement key="textField" stretchType="RelativeToTallestObject" x="210" y="0" width="86" height="16" uuid="223be44f-8565-40e3-9d43-0f13b4e159b7"/>
<box leftPadding="5" rightPadding="10">
<topPen lineWidth="0.25" lineColor="#999999"/>
<leftPen lineWidth="0.25" lineColor="#999999"/>
<bottomPen lineWidth="0.25" lineColor="#999999"/>
<rightPen lineWidth="0.25" lineColor="#999999"/>
</box>
<textElement textAlignment="Right">
<font fontName="Arial"/>
</textElement>
<textFieldExpression><![CDATA[$F{formattedCount}]]></textFieldExpression>
</textField>
</band>
</detail>
<columnFooter>
<band splitType="Stretch"/>
</columnFooter>
<pageFooter>
<band splitType="Stretch"/>
</pageFooter>
<summary>
<band splitType="Stretch"/>
</summary>
</jasperReport>
jasper-reports expression
I want to put a printWhenExpression on a static text based on a condition which says that print the label only if there is atleast a non null textField in a particular column in detail band.
Its like print the column header only if there is a non null field in that column.
I tried putting this expression: $F{textfield} != null
, but it works only for first record, if first record has null and second record has not null value then the label will be hidden, where as we want it to be displayed.
Please reply if you need any more info.
The below 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="IdpPdfSignature1" pageWidth="296" pageHeight="300" whenNoDataType="AllSectionsNoDetail" columnWidth="296" leftMargin="0" rightMargin="0" topMargin="0" bottomMargin="0" uuid="1c6e4be1-891b-4d0e-abfd-1c17f663d5be">
<property name="ireport.scriptlethandling" value="0"/>
<property name="ireport.encoding" value="UTF-8"/>
<import value="net.sf.jasperreports.engine.*"/>
<import value="java.util.*"/>
<import value="net.sf.jasperreports.engine.data.*"/>
<parameter name="mypic" class="java.io.InputStream" isForPrompting="false"/>
<parameter name="mypic1" class="java.io.InputStream" isForPrompting="false"/>
<parameter name="mypic2" class="java.io.InputStream" isForPrompting="false"/>
<parameter name="group" class="java.lang.String" isForPrompting="false"/>
<parameter name="device" class="java.lang.String" isForPrompting="false"/>
<parameter name="timeperiod" class="java.lang.String" isForPrompting="false"/>
<parameter name="customStartDate" class="java.util.Date" isForPrompting="false"/>
<parameter name="customEndDate" class="java.util.Date" isForPrompting="false"/>
<parameter name="footer" class="java.lang.String" isForPrompting="false"/>
<field name="signatureID" class="java.lang.String">
<fieldDescription><![CDATA[signatureID]]></fieldDescription>
</field>
<field name="signatureClassification" class="java.lang.String">
<fieldDescription><![CDATA[signatureClassification]]></fieldDescription>
</field>
<field name="description" class="java.lang.String">
<fieldDescription><![CDATA[description]]></fieldDescription>
</field>
<field name="count" class="java.lang.Long">
<fieldDescription><![CDATA[count]]></fieldDescription>
</field>
<field name="formattedCount" class="java.lang.String"/>
<field name="messageType" class="java.lang.String"/>
<variable name="mypic" class="java.io.InputStream"/>
<variable name="mypic1" class="java.io.InputStream"/>
<variable name="mypic2" class="java.io.InputStream"/>
<background>
<band splitType="Stretch"/>
</background>
<title>
<band splitType="Stretch"/>
</title>
<pageHeader>
<band splitType="Stretch"/>
</pageHeader>
<columnHeader>
<band height="16" splitType="Stretch">
<staticText>
<reportElement key="staticText-2" mode="Opaque" x="0" y="0" width="160" height="16" forecolor="#000000" backcolor="#CCCCCC" uuid="967c915b-1af1-4972-805f-0e3f365ba11c">
<printWhenExpression><![CDATA[new Boolean($F{messageType}!=null)]]></printWhenExpression>
</reportElement>
<box>
<pen lineWidth="0.25" lineColor="#000000"/>
<topPen lineWidth="0.25" lineColor="#000000"/>
<leftPen lineWidth="0.25" lineColor="#000000"/>
<bottomPen lineWidth="0.25" lineColor="#000000"/>
<rightPen lineWidth="0.25" lineColor="#000000"/>
</box>
<textElement textAlignment="Center" verticalAlignment="Middle">
<font fontName="Arial" size="10" isBold="true" pdfFontName="Helvetica-Bold"/>
</textElement>
<text><![CDATA[Signature Name]]></text>
</staticText>
<staticText>
<reportElement key="staticText-3" mode="Opaque" x="210" y="0" width="86" height="16" forecolor="#000000" backcolor="#CCCCCC" uuid="a998a72e-01fa-4c27-ad7e-1e3a6c3408d2"/>
<box>
<pen lineWidth="0.25" lineColor="#000000"/>
<topPen lineWidth="0.25" lineColor="#000000"/>
<leftPen lineWidth="0.25" lineColor="#000000"/>
<bottomPen lineWidth="0.25" lineColor="#000000"/>
<rightPen lineWidth="0.25" lineColor="#000000"/>
</box>
<textElement textAlignment="Center" verticalAlignment="Middle">
<font fontName="Arial" size="10" isBold="true" pdfFontName="Helvetica-Bold"/>
</textElement>
<text><![CDATA[Event Count]]></text>
</staticText>
<staticText>
<reportElement key="staticText-11" mode="Opaque" x="160" y="0" width="50" height="16" forecolor="#000000" backcolor="#CCCCCC" uuid="5170b4a6-3531-412d-9f8f-bc32dc4de0be">
<printWhenExpression><![CDATA[new Boolean($F{messageType}!=null)]]></printWhenExpression>
</reportElement>
<box>
<pen lineWidth="0.25" lineColor="#000000"/>
<topPen lineWidth="0.25" lineColor="#000000"/>
<leftPen lineWidth="0.25" lineColor="#000000"/>
<bottomPen lineWidth="0.25" lineColor="#000000"/>
<rightPen lineWidth="0.25" lineColor="#000000"/>
</box>
<textElement textAlignment="Center" verticalAlignment="Middle">
<font fontName="Arial" size="10" isBold="true" pdfFontName="Helvetica-Bold"/>
</textElement>
<text><![CDATA[Type]]></text>
</staticText>
</band>
</columnHeader>
<detail>
<band height="16" splitType="Stretch">
<textField isStretchWithOverflow="true" isBlankWhenNull="true">
<reportElement key="textField-7" stretchType="RelativeToTallestObject" x="160" y="0" width="50" height="16" uuid="917d3aff-44a7-4a26-865a-d466aff3ab00">
<printWhenExpression><![CDATA[new Boolean($F{messageType}!=null)]]></printWhenExpression>
</reportElement>
<box leftPadding="5">
<topPen lineWidth="0.25" lineColor="#999999"/>
<leftPen lineWidth="0.25" lineColor="#999999"/>
<bottomPen lineWidth="0.25" lineColor="#999999"/>
<rightPen lineWidth="0.25" lineColor="#999999"/>
</box>
<textElement textAlignment="Left">
<font fontName="Arial"/>
</textElement>
<textFieldExpression><![CDATA[$F{messageType}]]></textFieldExpression>
</textField>
<textField isStretchWithOverflow="true" isBlankWhenNull="true">
<reportElement key="textField" stretchType="RelativeToTallestObject" x="0" y="0" width="160" height="16" uuid="72492119-a45f-49c5-8fb8-19252c57e402">
<printWhenExpression><![CDATA[new Boolean($F{messageType}!=null)]]></printWhenExpression>
</reportElement>
<box leftPadding="5" rightPadding="10">
<topPen lineWidth="0.25" lineColor="#999999"/>
<leftPen lineWidth="0.25" lineColor="#999999"/>
<bottomPen lineWidth="0.25" lineColor="#999999"/>
<rightPen lineWidth="0.25" lineColor="#999999"/>
</box>
<textElement>
<font fontName="Arial"/>
</textElement>
<textFieldExpression><![CDATA[$F{signatureClassification}]]></textFieldExpression>
</textField>
<textField isStretchWithOverflow="true" isBlankWhenNull="true">
<reportElement key="textField" stretchType="RelativeToTallestObject" x="210" y="0" width="86" height="16" uuid="223be44f-8565-40e3-9d43-0f13b4e159b7"/>
<box leftPadding="5" rightPadding="10">
<topPen lineWidth="0.25" lineColor="#999999"/>
<leftPen lineWidth="0.25" lineColor="#999999"/>
<bottomPen lineWidth="0.25" lineColor="#999999"/>
<rightPen lineWidth="0.25" lineColor="#999999"/>
</box>
<textElement textAlignment="Right">
<font fontName="Arial"/>
</textElement>
<textFieldExpression><![CDATA[$F{formattedCount}]]></textFieldExpression>
</textField>
</band>
</detail>
<columnFooter>
<band splitType="Stretch"/>
</columnFooter>
<pageFooter>
<band splitType="Stretch"/>
</pageFooter>
<summary>
<band splitType="Stretch"/>
</summary>
</jasperReport>
jasper-reports expression
jasper-reports expression
edited May 30 '14 at 10:27
Alex K
18.3k1479153
18.3k1479153
asked May 30 '14 at 10:04
Ananta Ch. Swain
2114
2114
Possible duplicate of How to show/hide a column at runtime?
– Alex K
Jul 21 '16 at 21:11
add a comment |
Possible duplicate of How to show/hide a column at runtime?
– Alex K
Jul 21 '16 at 21:11
Possible duplicate of How to show/hide a column at runtime?
– Alex K
Jul 21 '16 at 21:11
Possible duplicate of How to show/hide a column at runtime?
– Alex K
Jul 21 '16 at 21:11
add a comment |
1 Answer
1
active
oldest
votes
You can use Table Component to achieve this instead of using Static text by giving print when condition under "Column Print When" property of Table's column Header.
i.e. Column Print When = $F{messageType}!=null
PFB corrected JRXML:
<summary>
<band height="55" splitType="Stretch">
<componentElement>
<reportElement uuid="632c8fad-e35f-4b89-b28e-b363b0711c06" x="0" y="0" width="270" height="55"/>
<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="Table Dataset 1" uuid="bf16282a-8672-46cb-9849-4966b5f8c969">
<dataSourceExpression><![CDATA[new net.sf.jasperreports.engine.JREmptyDataSource(1)]]></dataSourceExpression>
</datasetRun>
<jr:column width="90" uuid="00429e67-6d71-4b66-9eb4-22d0c649e7a4">
<jr:columnHeader height="30" rowSpan="1">
<staticText>
<reportElement uuid="a62a81ca-ceae-4178-9e4e-6ca17fc89c69" key="staticText-2" mode="Opaque" x="0" y="0" width="90" height="30" forecolor="#000000" backcolor="#CCCCCC">
<printWhenExpression><![CDATA[new Boolean($F{messageType}!=null)]]></printWhenExpression>
</reportElement>
<box>
<pen lineWidth="0.25" lineColor="#000000"/>
<topPen lineWidth="0.25" lineColor="#000000"/>
<leftPen lineWidth="0.25" lineColor="#000000"/>
<bottomPen lineWidth="0.25" lineColor="#000000"/>
<rightPen lineWidth="0.25" lineColor="#000000"/>
</box>
<textElement textAlignment="Center" verticalAlignment="Middle">
<font fontName="Arial" isBold="true" pdfFontName="Helvetica-Bold"/>
</textElement>
<text><![CDATA[Signature Name]]></text>
</staticText>
</jr:columnHeader>
<jr:detailCell height="20" rowSpan="1">
<textField isStretchWithOverflow="true" isBlankWhenNull="true">
<reportElement uuid="cb654043-45a4-4742-86ed-ed9818716db2" key="textField" stretchType="RelativeToTallestObject" x="0" y="0" width="90" height="20">
<printWhenExpression><![CDATA[new Boolean($F{messageType}!=null)]]></printWhenExpression>
</reportElement>
<box leftPadding="5" rightPadding="10">
<topPen lineWidth="0.25" lineColor="#999999"/>
<leftPen lineWidth="0.25" lineColor="#999999"/>
<bottomPen lineWidth="0.25" lineColor="#999999"/>
<rightPen lineWidth="0.25" lineColor="#999999"/>
</box>
<textElement>
<font fontName="Arial"/>
</textElement>
<textFieldExpression><![CDATA[$F{signatureClassification}]]></textFieldExpression>
</textField>
</jr:detailCell>
</jr:column>
<jr:column width="90" uuid="7ebf1fdd-52e5-43da-96f0-1c01a7cb0876">
<printWhenExpression><![CDATA[$F{messageType}!=null]]></printWhenExpression>
<jr:columnHeader height="30" rowSpan="1">
<staticText>
<reportElement uuid="d96cce84-1318-49aa-a6d2-3a17e4329ef3" key="staticText-11" mode="Opaque" x="0" y="0" width="90" height="30" forecolor="#000000" backcolor="#CCCCCC">
<printWhenExpression><![CDATA[new Boolean($F{messageType}!=null)]]></printWhenExpression>
</reportElement>
<box>
<pen lineWidth="0.25" lineColor="#000000"/>
<topPen lineWidth="0.25" lineColor="#000000"/>
<leftPen lineWidth="0.25" lineColor="#000000"/>
<bottomPen lineWidth="0.25" lineColor="#000000"/>
<rightPen lineWidth="0.25" lineColor="#000000"/>
</box>
<textElement textAlignment="Center" verticalAlignment="Middle">
<font fontName="Arial" isBold="true" pdfFontName="Helvetica-Bold"/>
</textElement>
<text><![CDATA[Type]]></text>
</staticText>
</jr:columnHeader>
<jr:detailCell height="20" rowSpan="1">
<textField isStretchWithOverflow="true" isBlankWhenNull="true">
<reportElement uuid="4832a90d-505e-4f13-87bf-0a7fe6e3a00f" key="textField-7" stretchType="RelativeToTallestObject" x="0" y="0" width="90" height="20">
<printWhenExpression><![CDATA[$F{messageType}]]></printWhenExpression>
</reportElement>
<box leftPadding="5">
<topPen lineWidth="0.25" lineColor="#999999"/>
<leftPen lineWidth="0.25" lineColor="#999999"/>
<bottomPen lineWidth="0.25" lineColor="#999999"/>
<rightPen lineWidth="0.25" lineColor="#999999"/>
</box>
<textElement textAlignment="Left">
<font fontName="Arial"/>
</textElement>
<textFieldExpression><![CDATA[$F{messageType}]]></textFieldExpression>
</textField>
</jr:detailCell>
</jr:column>
<jr:column width="90" uuid="89b50640-0509-4b61-8aa3-aa68eb3e6685">
<jr:columnHeader height="30" rowSpan="1">
<staticText>
<reportElement uuid="fe68d8bf-3f0d-4202-a53c-8c6f328e4d16" key="staticText-3" mode="Opaque" x="0" y="0" width="90" height="30" forecolor="#000000" backcolor="#CCCCCC"/>
<box>
<pen lineWidth="0.25" lineColor="#000000"/>
<topPen lineWidth="0.25" lineColor="#000000"/>
<leftPen lineWidth="0.25" lineColor="#000000"/>
<bottomPen lineWidth="0.25" lineColor="#000000"/>
<rightPen lineWidth="0.25" lineColor="#000000"/>
</box>
<textElement textAlignment="Center" verticalAlignment="Middle">
<font fontName="Arial" isBold="true" pdfFontName="Helvetica-Bold"/>
</textElement>
<text><![CDATA[Event Count]]></text>
</staticText>
</jr:columnHeader>
<jr:detailCell height="20" rowSpan="1">
<textField isStretchWithOverflow="true" isBlankWhenNull="true">
<reportElement uuid="169af53a-b587-4d63-93f8-cb9296c89f4c" key="textField" stretchType="RelativeToTallestObject" x="0" y="0" width="90" height="20"/>
<box leftPadding="5" rightPadding="10">
<topPen lineWidth="0.25" lineColor="#999999"/>
<leftPen lineWidth="0.25" lineColor="#999999"/>
<bottomPen lineWidth="0.25" lineColor="#999999"/>
<rightPen lineWidth="0.25" lineColor="#999999"/>
</box>
<textElement textAlignment="Right">
<font fontName="Arial"/>
</textElement>
<textFieldExpression><![CDATA[$F{formattedCount}]]></textFieldExpression>
</textField>
</jr:detailCell>
</jr:column>
</jr:table>
</componentElement>
</band>
</summary>
Hope this resolve your issue.
Regards,
Srikanth Kattam
add a comment |
Your Answer
StackExchange.ifUsing("editor", function () {
StackExchange.using("externalEditor", function () {
StackExchange.using("snippets", function () {
StackExchange.snippets.init();
});
});
}, "code-snippets");
StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "1"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);
StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});
function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});
}
});
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f23951958%2fprint-when-expression-to-display-static-text-if-there-is-atleast-a-not-null-fiel%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
1 Answer
1
active
oldest
votes
1 Answer
1
active
oldest
votes
active
oldest
votes
active
oldest
votes
You can use Table Component to achieve this instead of using Static text by giving print when condition under "Column Print When" property of Table's column Header.
i.e. Column Print When = $F{messageType}!=null
PFB corrected JRXML:
<summary>
<band height="55" splitType="Stretch">
<componentElement>
<reportElement uuid="632c8fad-e35f-4b89-b28e-b363b0711c06" x="0" y="0" width="270" height="55"/>
<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="Table Dataset 1" uuid="bf16282a-8672-46cb-9849-4966b5f8c969">
<dataSourceExpression><![CDATA[new net.sf.jasperreports.engine.JREmptyDataSource(1)]]></dataSourceExpression>
</datasetRun>
<jr:column width="90" uuid="00429e67-6d71-4b66-9eb4-22d0c649e7a4">
<jr:columnHeader height="30" rowSpan="1">
<staticText>
<reportElement uuid="a62a81ca-ceae-4178-9e4e-6ca17fc89c69" key="staticText-2" mode="Opaque" x="0" y="0" width="90" height="30" forecolor="#000000" backcolor="#CCCCCC">
<printWhenExpression><![CDATA[new Boolean($F{messageType}!=null)]]></printWhenExpression>
</reportElement>
<box>
<pen lineWidth="0.25" lineColor="#000000"/>
<topPen lineWidth="0.25" lineColor="#000000"/>
<leftPen lineWidth="0.25" lineColor="#000000"/>
<bottomPen lineWidth="0.25" lineColor="#000000"/>
<rightPen lineWidth="0.25" lineColor="#000000"/>
</box>
<textElement textAlignment="Center" verticalAlignment="Middle">
<font fontName="Arial" isBold="true" pdfFontName="Helvetica-Bold"/>
</textElement>
<text><![CDATA[Signature Name]]></text>
</staticText>
</jr:columnHeader>
<jr:detailCell height="20" rowSpan="1">
<textField isStretchWithOverflow="true" isBlankWhenNull="true">
<reportElement uuid="cb654043-45a4-4742-86ed-ed9818716db2" key="textField" stretchType="RelativeToTallestObject" x="0" y="0" width="90" height="20">
<printWhenExpression><![CDATA[new Boolean($F{messageType}!=null)]]></printWhenExpression>
</reportElement>
<box leftPadding="5" rightPadding="10">
<topPen lineWidth="0.25" lineColor="#999999"/>
<leftPen lineWidth="0.25" lineColor="#999999"/>
<bottomPen lineWidth="0.25" lineColor="#999999"/>
<rightPen lineWidth="0.25" lineColor="#999999"/>
</box>
<textElement>
<font fontName="Arial"/>
</textElement>
<textFieldExpression><![CDATA[$F{signatureClassification}]]></textFieldExpression>
</textField>
</jr:detailCell>
</jr:column>
<jr:column width="90" uuid="7ebf1fdd-52e5-43da-96f0-1c01a7cb0876">
<printWhenExpression><![CDATA[$F{messageType}!=null]]></printWhenExpression>
<jr:columnHeader height="30" rowSpan="1">
<staticText>
<reportElement uuid="d96cce84-1318-49aa-a6d2-3a17e4329ef3" key="staticText-11" mode="Opaque" x="0" y="0" width="90" height="30" forecolor="#000000" backcolor="#CCCCCC">
<printWhenExpression><![CDATA[new Boolean($F{messageType}!=null)]]></printWhenExpression>
</reportElement>
<box>
<pen lineWidth="0.25" lineColor="#000000"/>
<topPen lineWidth="0.25" lineColor="#000000"/>
<leftPen lineWidth="0.25" lineColor="#000000"/>
<bottomPen lineWidth="0.25" lineColor="#000000"/>
<rightPen lineWidth="0.25" lineColor="#000000"/>
</box>
<textElement textAlignment="Center" verticalAlignment="Middle">
<font fontName="Arial" isBold="true" pdfFontName="Helvetica-Bold"/>
</textElement>
<text><![CDATA[Type]]></text>
</staticText>
</jr:columnHeader>
<jr:detailCell height="20" rowSpan="1">
<textField isStretchWithOverflow="true" isBlankWhenNull="true">
<reportElement uuid="4832a90d-505e-4f13-87bf-0a7fe6e3a00f" key="textField-7" stretchType="RelativeToTallestObject" x="0" y="0" width="90" height="20">
<printWhenExpression><![CDATA[$F{messageType}]]></printWhenExpression>
</reportElement>
<box leftPadding="5">
<topPen lineWidth="0.25" lineColor="#999999"/>
<leftPen lineWidth="0.25" lineColor="#999999"/>
<bottomPen lineWidth="0.25" lineColor="#999999"/>
<rightPen lineWidth="0.25" lineColor="#999999"/>
</box>
<textElement textAlignment="Left">
<font fontName="Arial"/>
</textElement>
<textFieldExpression><![CDATA[$F{messageType}]]></textFieldExpression>
</textField>
</jr:detailCell>
</jr:column>
<jr:column width="90" uuid="89b50640-0509-4b61-8aa3-aa68eb3e6685">
<jr:columnHeader height="30" rowSpan="1">
<staticText>
<reportElement uuid="fe68d8bf-3f0d-4202-a53c-8c6f328e4d16" key="staticText-3" mode="Opaque" x="0" y="0" width="90" height="30" forecolor="#000000" backcolor="#CCCCCC"/>
<box>
<pen lineWidth="0.25" lineColor="#000000"/>
<topPen lineWidth="0.25" lineColor="#000000"/>
<leftPen lineWidth="0.25" lineColor="#000000"/>
<bottomPen lineWidth="0.25" lineColor="#000000"/>
<rightPen lineWidth="0.25" lineColor="#000000"/>
</box>
<textElement textAlignment="Center" verticalAlignment="Middle">
<font fontName="Arial" isBold="true" pdfFontName="Helvetica-Bold"/>
</textElement>
<text><![CDATA[Event Count]]></text>
</staticText>
</jr:columnHeader>
<jr:detailCell height="20" rowSpan="1">
<textField isStretchWithOverflow="true" isBlankWhenNull="true">
<reportElement uuid="169af53a-b587-4d63-93f8-cb9296c89f4c" key="textField" stretchType="RelativeToTallestObject" x="0" y="0" width="90" height="20"/>
<box leftPadding="5" rightPadding="10">
<topPen lineWidth="0.25" lineColor="#999999"/>
<leftPen lineWidth="0.25" lineColor="#999999"/>
<bottomPen lineWidth="0.25" lineColor="#999999"/>
<rightPen lineWidth="0.25" lineColor="#999999"/>
</box>
<textElement textAlignment="Right">
<font fontName="Arial"/>
</textElement>
<textFieldExpression><![CDATA[$F{formattedCount}]]></textFieldExpression>
</textField>
</jr:detailCell>
</jr:column>
</jr:table>
</componentElement>
</band>
</summary>
Hope this resolve your issue.
Regards,
Srikanth Kattam
add a comment |
You can use Table Component to achieve this instead of using Static text by giving print when condition under "Column Print When" property of Table's column Header.
i.e. Column Print When = $F{messageType}!=null
PFB corrected JRXML:
<summary>
<band height="55" splitType="Stretch">
<componentElement>
<reportElement uuid="632c8fad-e35f-4b89-b28e-b363b0711c06" x="0" y="0" width="270" height="55"/>
<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="Table Dataset 1" uuid="bf16282a-8672-46cb-9849-4966b5f8c969">
<dataSourceExpression><![CDATA[new net.sf.jasperreports.engine.JREmptyDataSource(1)]]></dataSourceExpression>
</datasetRun>
<jr:column width="90" uuid="00429e67-6d71-4b66-9eb4-22d0c649e7a4">
<jr:columnHeader height="30" rowSpan="1">
<staticText>
<reportElement uuid="a62a81ca-ceae-4178-9e4e-6ca17fc89c69" key="staticText-2" mode="Opaque" x="0" y="0" width="90" height="30" forecolor="#000000" backcolor="#CCCCCC">
<printWhenExpression><![CDATA[new Boolean($F{messageType}!=null)]]></printWhenExpression>
</reportElement>
<box>
<pen lineWidth="0.25" lineColor="#000000"/>
<topPen lineWidth="0.25" lineColor="#000000"/>
<leftPen lineWidth="0.25" lineColor="#000000"/>
<bottomPen lineWidth="0.25" lineColor="#000000"/>
<rightPen lineWidth="0.25" lineColor="#000000"/>
</box>
<textElement textAlignment="Center" verticalAlignment="Middle">
<font fontName="Arial" isBold="true" pdfFontName="Helvetica-Bold"/>
</textElement>
<text><![CDATA[Signature Name]]></text>
</staticText>
</jr:columnHeader>
<jr:detailCell height="20" rowSpan="1">
<textField isStretchWithOverflow="true" isBlankWhenNull="true">
<reportElement uuid="cb654043-45a4-4742-86ed-ed9818716db2" key="textField" stretchType="RelativeToTallestObject" x="0" y="0" width="90" height="20">
<printWhenExpression><![CDATA[new Boolean($F{messageType}!=null)]]></printWhenExpression>
</reportElement>
<box leftPadding="5" rightPadding="10">
<topPen lineWidth="0.25" lineColor="#999999"/>
<leftPen lineWidth="0.25" lineColor="#999999"/>
<bottomPen lineWidth="0.25" lineColor="#999999"/>
<rightPen lineWidth="0.25" lineColor="#999999"/>
</box>
<textElement>
<font fontName="Arial"/>
</textElement>
<textFieldExpression><![CDATA[$F{signatureClassification}]]></textFieldExpression>
</textField>
</jr:detailCell>
</jr:column>
<jr:column width="90" uuid="7ebf1fdd-52e5-43da-96f0-1c01a7cb0876">
<printWhenExpression><![CDATA[$F{messageType}!=null]]></printWhenExpression>
<jr:columnHeader height="30" rowSpan="1">
<staticText>
<reportElement uuid="d96cce84-1318-49aa-a6d2-3a17e4329ef3" key="staticText-11" mode="Opaque" x="0" y="0" width="90" height="30" forecolor="#000000" backcolor="#CCCCCC">
<printWhenExpression><![CDATA[new Boolean($F{messageType}!=null)]]></printWhenExpression>
</reportElement>
<box>
<pen lineWidth="0.25" lineColor="#000000"/>
<topPen lineWidth="0.25" lineColor="#000000"/>
<leftPen lineWidth="0.25" lineColor="#000000"/>
<bottomPen lineWidth="0.25" lineColor="#000000"/>
<rightPen lineWidth="0.25" lineColor="#000000"/>
</box>
<textElement textAlignment="Center" verticalAlignment="Middle">
<font fontName="Arial" isBold="true" pdfFontName="Helvetica-Bold"/>
</textElement>
<text><![CDATA[Type]]></text>
</staticText>
</jr:columnHeader>
<jr:detailCell height="20" rowSpan="1">
<textField isStretchWithOverflow="true" isBlankWhenNull="true">
<reportElement uuid="4832a90d-505e-4f13-87bf-0a7fe6e3a00f" key="textField-7" stretchType="RelativeToTallestObject" x="0" y="0" width="90" height="20">
<printWhenExpression><![CDATA[$F{messageType}]]></printWhenExpression>
</reportElement>
<box leftPadding="5">
<topPen lineWidth="0.25" lineColor="#999999"/>
<leftPen lineWidth="0.25" lineColor="#999999"/>
<bottomPen lineWidth="0.25" lineColor="#999999"/>
<rightPen lineWidth="0.25" lineColor="#999999"/>
</box>
<textElement textAlignment="Left">
<font fontName="Arial"/>
</textElement>
<textFieldExpression><![CDATA[$F{messageType}]]></textFieldExpression>
</textField>
</jr:detailCell>
</jr:column>
<jr:column width="90" uuid="89b50640-0509-4b61-8aa3-aa68eb3e6685">
<jr:columnHeader height="30" rowSpan="1">
<staticText>
<reportElement uuid="fe68d8bf-3f0d-4202-a53c-8c6f328e4d16" key="staticText-3" mode="Opaque" x="0" y="0" width="90" height="30" forecolor="#000000" backcolor="#CCCCCC"/>
<box>
<pen lineWidth="0.25" lineColor="#000000"/>
<topPen lineWidth="0.25" lineColor="#000000"/>
<leftPen lineWidth="0.25" lineColor="#000000"/>
<bottomPen lineWidth="0.25" lineColor="#000000"/>
<rightPen lineWidth="0.25" lineColor="#000000"/>
</box>
<textElement textAlignment="Center" verticalAlignment="Middle">
<font fontName="Arial" isBold="true" pdfFontName="Helvetica-Bold"/>
</textElement>
<text><![CDATA[Event Count]]></text>
</staticText>
</jr:columnHeader>
<jr:detailCell height="20" rowSpan="1">
<textField isStretchWithOverflow="true" isBlankWhenNull="true">
<reportElement uuid="169af53a-b587-4d63-93f8-cb9296c89f4c" key="textField" stretchType="RelativeToTallestObject" x="0" y="0" width="90" height="20"/>
<box leftPadding="5" rightPadding="10">
<topPen lineWidth="0.25" lineColor="#999999"/>
<leftPen lineWidth="0.25" lineColor="#999999"/>
<bottomPen lineWidth="0.25" lineColor="#999999"/>
<rightPen lineWidth="0.25" lineColor="#999999"/>
</box>
<textElement textAlignment="Right">
<font fontName="Arial"/>
</textElement>
<textFieldExpression><![CDATA[$F{formattedCount}]]></textFieldExpression>
</textField>
</jr:detailCell>
</jr:column>
</jr:table>
</componentElement>
</band>
</summary>
Hope this resolve your issue.
Regards,
Srikanth Kattam
add a comment |
You can use Table Component to achieve this instead of using Static text by giving print when condition under "Column Print When" property of Table's column Header.
i.e. Column Print When = $F{messageType}!=null
PFB corrected JRXML:
<summary>
<band height="55" splitType="Stretch">
<componentElement>
<reportElement uuid="632c8fad-e35f-4b89-b28e-b363b0711c06" x="0" y="0" width="270" height="55"/>
<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="Table Dataset 1" uuid="bf16282a-8672-46cb-9849-4966b5f8c969">
<dataSourceExpression><![CDATA[new net.sf.jasperreports.engine.JREmptyDataSource(1)]]></dataSourceExpression>
</datasetRun>
<jr:column width="90" uuid="00429e67-6d71-4b66-9eb4-22d0c649e7a4">
<jr:columnHeader height="30" rowSpan="1">
<staticText>
<reportElement uuid="a62a81ca-ceae-4178-9e4e-6ca17fc89c69" key="staticText-2" mode="Opaque" x="0" y="0" width="90" height="30" forecolor="#000000" backcolor="#CCCCCC">
<printWhenExpression><![CDATA[new Boolean($F{messageType}!=null)]]></printWhenExpression>
</reportElement>
<box>
<pen lineWidth="0.25" lineColor="#000000"/>
<topPen lineWidth="0.25" lineColor="#000000"/>
<leftPen lineWidth="0.25" lineColor="#000000"/>
<bottomPen lineWidth="0.25" lineColor="#000000"/>
<rightPen lineWidth="0.25" lineColor="#000000"/>
</box>
<textElement textAlignment="Center" verticalAlignment="Middle">
<font fontName="Arial" isBold="true" pdfFontName="Helvetica-Bold"/>
</textElement>
<text><![CDATA[Signature Name]]></text>
</staticText>
</jr:columnHeader>
<jr:detailCell height="20" rowSpan="1">
<textField isStretchWithOverflow="true" isBlankWhenNull="true">
<reportElement uuid="cb654043-45a4-4742-86ed-ed9818716db2" key="textField" stretchType="RelativeToTallestObject" x="0" y="0" width="90" height="20">
<printWhenExpression><![CDATA[new Boolean($F{messageType}!=null)]]></printWhenExpression>
</reportElement>
<box leftPadding="5" rightPadding="10">
<topPen lineWidth="0.25" lineColor="#999999"/>
<leftPen lineWidth="0.25" lineColor="#999999"/>
<bottomPen lineWidth="0.25" lineColor="#999999"/>
<rightPen lineWidth="0.25" lineColor="#999999"/>
</box>
<textElement>
<font fontName="Arial"/>
</textElement>
<textFieldExpression><![CDATA[$F{signatureClassification}]]></textFieldExpression>
</textField>
</jr:detailCell>
</jr:column>
<jr:column width="90" uuid="7ebf1fdd-52e5-43da-96f0-1c01a7cb0876">
<printWhenExpression><![CDATA[$F{messageType}!=null]]></printWhenExpression>
<jr:columnHeader height="30" rowSpan="1">
<staticText>
<reportElement uuid="d96cce84-1318-49aa-a6d2-3a17e4329ef3" key="staticText-11" mode="Opaque" x="0" y="0" width="90" height="30" forecolor="#000000" backcolor="#CCCCCC">
<printWhenExpression><![CDATA[new Boolean($F{messageType}!=null)]]></printWhenExpression>
</reportElement>
<box>
<pen lineWidth="0.25" lineColor="#000000"/>
<topPen lineWidth="0.25" lineColor="#000000"/>
<leftPen lineWidth="0.25" lineColor="#000000"/>
<bottomPen lineWidth="0.25" lineColor="#000000"/>
<rightPen lineWidth="0.25" lineColor="#000000"/>
</box>
<textElement textAlignment="Center" verticalAlignment="Middle">
<font fontName="Arial" isBold="true" pdfFontName="Helvetica-Bold"/>
</textElement>
<text><![CDATA[Type]]></text>
</staticText>
</jr:columnHeader>
<jr:detailCell height="20" rowSpan="1">
<textField isStretchWithOverflow="true" isBlankWhenNull="true">
<reportElement uuid="4832a90d-505e-4f13-87bf-0a7fe6e3a00f" key="textField-7" stretchType="RelativeToTallestObject" x="0" y="0" width="90" height="20">
<printWhenExpression><![CDATA[$F{messageType}]]></printWhenExpression>
</reportElement>
<box leftPadding="5">
<topPen lineWidth="0.25" lineColor="#999999"/>
<leftPen lineWidth="0.25" lineColor="#999999"/>
<bottomPen lineWidth="0.25" lineColor="#999999"/>
<rightPen lineWidth="0.25" lineColor="#999999"/>
</box>
<textElement textAlignment="Left">
<font fontName="Arial"/>
</textElement>
<textFieldExpression><![CDATA[$F{messageType}]]></textFieldExpression>
</textField>
</jr:detailCell>
</jr:column>
<jr:column width="90" uuid="89b50640-0509-4b61-8aa3-aa68eb3e6685">
<jr:columnHeader height="30" rowSpan="1">
<staticText>
<reportElement uuid="fe68d8bf-3f0d-4202-a53c-8c6f328e4d16" key="staticText-3" mode="Opaque" x="0" y="0" width="90" height="30" forecolor="#000000" backcolor="#CCCCCC"/>
<box>
<pen lineWidth="0.25" lineColor="#000000"/>
<topPen lineWidth="0.25" lineColor="#000000"/>
<leftPen lineWidth="0.25" lineColor="#000000"/>
<bottomPen lineWidth="0.25" lineColor="#000000"/>
<rightPen lineWidth="0.25" lineColor="#000000"/>
</box>
<textElement textAlignment="Center" verticalAlignment="Middle">
<font fontName="Arial" isBold="true" pdfFontName="Helvetica-Bold"/>
</textElement>
<text><![CDATA[Event Count]]></text>
</staticText>
</jr:columnHeader>
<jr:detailCell height="20" rowSpan="1">
<textField isStretchWithOverflow="true" isBlankWhenNull="true">
<reportElement uuid="169af53a-b587-4d63-93f8-cb9296c89f4c" key="textField" stretchType="RelativeToTallestObject" x="0" y="0" width="90" height="20"/>
<box leftPadding="5" rightPadding="10">
<topPen lineWidth="0.25" lineColor="#999999"/>
<leftPen lineWidth="0.25" lineColor="#999999"/>
<bottomPen lineWidth="0.25" lineColor="#999999"/>
<rightPen lineWidth="0.25" lineColor="#999999"/>
</box>
<textElement textAlignment="Right">
<font fontName="Arial"/>
</textElement>
<textFieldExpression><![CDATA[$F{formattedCount}]]></textFieldExpression>
</textField>
</jr:detailCell>
</jr:column>
</jr:table>
</componentElement>
</band>
</summary>
Hope this resolve your issue.
Regards,
Srikanth Kattam
You can use Table Component to achieve this instead of using Static text by giving print when condition under "Column Print When" property of Table's column Header.
i.e. Column Print When = $F{messageType}!=null
PFB corrected JRXML:
<summary>
<band height="55" splitType="Stretch">
<componentElement>
<reportElement uuid="632c8fad-e35f-4b89-b28e-b363b0711c06" x="0" y="0" width="270" height="55"/>
<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="Table Dataset 1" uuid="bf16282a-8672-46cb-9849-4966b5f8c969">
<dataSourceExpression><![CDATA[new net.sf.jasperreports.engine.JREmptyDataSource(1)]]></dataSourceExpression>
</datasetRun>
<jr:column width="90" uuid="00429e67-6d71-4b66-9eb4-22d0c649e7a4">
<jr:columnHeader height="30" rowSpan="1">
<staticText>
<reportElement uuid="a62a81ca-ceae-4178-9e4e-6ca17fc89c69" key="staticText-2" mode="Opaque" x="0" y="0" width="90" height="30" forecolor="#000000" backcolor="#CCCCCC">
<printWhenExpression><![CDATA[new Boolean($F{messageType}!=null)]]></printWhenExpression>
</reportElement>
<box>
<pen lineWidth="0.25" lineColor="#000000"/>
<topPen lineWidth="0.25" lineColor="#000000"/>
<leftPen lineWidth="0.25" lineColor="#000000"/>
<bottomPen lineWidth="0.25" lineColor="#000000"/>
<rightPen lineWidth="0.25" lineColor="#000000"/>
</box>
<textElement textAlignment="Center" verticalAlignment="Middle">
<font fontName="Arial" isBold="true" pdfFontName="Helvetica-Bold"/>
</textElement>
<text><![CDATA[Signature Name]]></text>
</staticText>
</jr:columnHeader>
<jr:detailCell height="20" rowSpan="1">
<textField isStretchWithOverflow="true" isBlankWhenNull="true">
<reportElement uuid="cb654043-45a4-4742-86ed-ed9818716db2" key="textField" stretchType="RelativeToTallestObject" x="0" y="0" width="90" height="20">
<printWhenExpression><![CDATA[new Boolean($F{messageType}!=null)]]></printWhenExpression>
</reportElement>
<box leftPadding="5" rightPadding="10">
<topPen lineWidth="0.25" lineColor="#999999"/>
<leftPen lineWidth="0.25" lineColor="#999999"/>
<bottomPen lineWidth="0.25" lineColor="#999999"/>
<rightPen lineWidth="0.25" lineColor="#999999"/>
</box>
<textElement>
<font fontName="Arial"/>
</textElement>
<textFieldExpression><![CDATA[$F{signatureClassification}]]></textFieldExpression>
</textField>
</jr:detailCell>
</jr:column>
<jr:column width="90" uuid="7ebf1fdd-52e5-43da-96f0-1c01a7cb0876">
<printWhenExpression><![CDATA[$F{messageType}!=null]]></printWhenExpression>
<jr:columnHeader height="30" rowSpan="1">
<staticText>
<reportElement uuid="d96cce84-1318-49aa-a6d2-3a17e4329ef3" key="staticText-11" mode="Opaque" x="0" y="0" width="90" height="30" forecolor="#000000" backcolor="#CCCCCC">
<printWhenExpression><![CDATA[new Boolean($F{messageType}!=null)]]></printWhenExpression>
</reportElement>
<box>
<pen lineWidth="0.25" lineColor="#000000"/>
<topPen lineWidth="0.25" lineColor="#000000"/>
<leftPen lineWidth="0.25" lineColor="#000000"/>
<bottomPen lineWidth="0.25" lineColor="#000000"/>
<rightPen lineWidth="0.25" lineColor="#000000"/>
</box>
<textElement textAlignment="Center" verticalAlignment="Middle">
<font fontName="Arial" isBold="true" pdfFontName="Helvetica-Bold"/>
</textElement>
<text><![CDATA[Type]]></text>
</staticText>
</jr:columnHeader>
<jr:detailCell height="20" rowSpan="1">
<textField isStretchWithOverflow="true" isBlankWhenNull="true">
<reportElement uuid="4832a90d-505e-4f13-87bf-0a7fe6e3a00f" key="textField-7" stretchType="RelativeToTallestObject" x="0" y="0" width="90" height="20">
<printWhenExpression><![CDATA[$F{messageType}]]></printWhenExpression>
</reportElement>
<box leftPadding="5">
<topPen lineWidth="0.25" lineColor="#999999"/>
<leftPen lineWidth="0.25" lineColor="#999999"/>
<bottomPen lineWidth="0.25" lineColor="#999999"/>
<rightPen lineWidth="0.25" lineColor="#999999"/>
</box>
<textElement textAlignment="Left">
<font fontName="Arial"/>
</textElement>
<textFieldExpression><![CDATA[$F{messageType}]]></textFieldExpression>
</textField>
</jr:detailCell>
</jr:column>
<jr:column width="90" uuid="89b50640-0509-4b61-8aa3-aa68eb3e6685">
<jr:columnHeader height="30" rowSpan="1">
<staticText>
<reportElement uuid="fe68d8bf-3f0d-4202-a53c-8c6f328e4d16" key="staticText-3" mode="Opaque" x="0" y="0" width="90" height="30" forecolor="#000000" backcolor="#CCCCCC"/>
<box>
<pen lineWidth="0.25" lineColor="#000000"/>
<topPen lineWidth="0.25" lineColor="#000000"/>
<leftPen lineWidth="0.25" lineColor="#000000"/>
<bottomPen lineWidth="0.25" lineColor="#000000"/>
<rightPen lineWidth="0.25" lineColor="#000000"/>
</box>
<textElement textAlignment="Center" verticalAlignment="Middle">
<font fontName="Arial" isBold="true" pdfFontName="Helvetica-Bold"/>
</textElement>
<text><![CDATA[Event Count]]></text>
</staticText>
</jr:columnHeader>
<jr:detailCell height="20" rowSpan="1">
<textField isStretchWithOverflow="true" isBlankWhenNull="true">
<reportElement uuid="169af53a-b587-4d63-93f8-cb9296c89f4c" key="textField" stretchType="RelativeToTallestObject" x="0" y="0" width="90" height="20"/>
<box leftPadding="5" rightPadding="10">
<topPen lineWidth="0.25" lineColor="#999999"/>
<leftPen lineWidth="0.25" lineColor="#999999"/>
<bottomPen lineWidth="0.25" lineColor="#999999"/>
<rightPen lineWidth="0.25" lineColor="#999999"/>
</box>
<textElement textAlignment="Right">
<font fontName="Arial"/>
</textElement>
<textFieldExpression><![CDATA[$F{formattedCount}]]></textFieldExpression>
</textField>
</jr:detailCell>
</jr:column>
</jr:table>
</componentElement>
</band>
</summary>
Hope this resolve your issue.
Regards,
Srikanth Kattam
edited Jun 3 '14 at 10:01
answered Jun 3 '14 at 9:55
user3702468
112
112
add a comment |
add a comment |
Thanks for contributing an answer to Stack Overflow!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Some of your past answers have not been well-received, and you're in danger of being blocked from answering.
Please pay close attention to the following guidance:
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f23951958%2fprint-when-expression-to-display-static-text-if-there-is-atleast-a-not-null-fiel%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Possible duplicate of How to show/hide a column at runtime?
– Alex K
Jul 21 '16 at 21:11