Jump to content
Changes to the Jaspersoft community edition download ×

How to display message when no data available in list


patchy_9

Recommended Posts

 Hello,

 I'm using list to display data grid of the report.

 I would like to display the message "no data available" below the column headers when there is no data return in the list.

 I also would like to show "n/a" when some of the data fields are not avaliable.

 I'm using text field expression below to show "n/a" but it's not working. it displays blank.

<textFieldExpression><![CDATA[$F{status}==null? "N/A":$F{status}]]></textFieldExpression>[/code]

Please give me suggestions.

 

download_26.png.6353cbe3a3cf9a83a21f77d0148facb7.png

<?xml version="1.0" encoding="UTF-8"?><!-- Created with Jaspersoft Studio version 6.3.0.final using JasperReports Library version 6.2.0  --><!-- 2016-12-29T14:11:03 --><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="Tree" pageWidth="595" pageHeight="842" columnWidth="535"              leftMargin="20" rightMargin="20" topMargin="20" bottomMargin="20"              uuid="2f6e4db4-9f8f-4ffe-9759-6e1fd142f492">    <property name="template.type" value="columnar"/>    <property name="com.jaspersoft.studio.data.defaultdataadapter" value="data1.xml"/>    <style name="Title"         forecolor="#000000" fontName="Times New Roman" fontSize="50" isBold="false"/>    <style name="SubTitle"      forecolor="#666666" fontName="Times New Roman" fontSize="18" isBold="false"/>    <style name="Column header" forecolor="#666666" fontName="Times New Roman" fontSize="14" isBold="true"/>    <style name="Detail" mode="Transparent"         fontName="Times New Roman"/>    <style name="Row"    mode="Transparent"         fontName="Times New Roman" pdfFontName="Times-Roman">        <conditionalStyle>            <conditionExpression><![CDATA[$V{REPORT_COUNT}%2 == 0]]></conditionExpression>            <style mode="Opaque" backcolor="#F0EFEF"/>        </conditionalStyle>    </style>    <subDataset name="Dataset1" uuid="005256a7-9487-4222-8eca-79f800eb8b30">        <property name="com.jaspersoft.studio.data.defaultdataadapter" value="reportTest"/>        <queryString language="json">            <![CDATA[user.list]]>        </queryString>        <field name="id" class="java.lang.String">            <fieldDescription><![CDATA[id]]></fieldDescription>        </field>        <field name="date" class="java.lang.String">            <fieldDescription><![CDATA[date]]></fieldDescription>        </field>        <field name="status" class="java.lang.String">            <fieldDescription><![CDATA[status]]></fieldDescription>        </field>    </subDataset>    <queryString language="json">        <![CDATA[user]]>    </queryString>    <field name="id" class="java.lang.String">        <fieldDescription><![CDATA[id]]></fieldDescription>    </field>    <field name="first" class="java.lang.String">        <fieldDescription><![CDATA[first]]></fieldDescription>    </field>    <field name="last" class="java.lang.String">        <fieldDescription><![CDATA[last]]></fieldDescription>    </field>    <field name="addressLine1" class="java.lang.String">        <fieldDescription><![CDATA[addresses.addressLine1]]></fieldDescription>    </field>    <field name="addressLine2" class="java.lang.String">        <fieldDescription><![CDATA[addresses.addressLine2]]></fieldDescription>    </field>    <field name="addressLine3" class="java.lang.String">        <fieldDescription><![CDATA[addresses.addressLine3]]></fieldDescription>    </field>    <field name="city" class="java.lang.String">        <fieldDescription><![CDATA[addresses.city]]></fieldDescription>    </field>    <field name="state" class="java.lang.String">        <fieldDescription><![CDATA[addresses.state]]></fieldDescription>    </field>    <field name="zip" class="java.lang.String">        <fieldDescription><![CDATA[addresses.zip]]></fieldDescription>    </field>    <field name="phone1" class="java.lang.String">        <fieldDescription><![CDATA[phone.telephone1]]></fieldDescription>    </field>    <field name="phone2" class="java.lang.String">        <fieldDescription><![CDATA[phone.telephone2]]></fieldDescription>    </field>    <field name="phone3" class="java.lang.String">        <fieldDescription><![CDATA[phone.telephone3]]></fieldDescription>    </field>    <background>        <band splitType="Stretch"/>    </background>    <pageHeader>        <band height="29">            <staticText>                <reportElement style="SubTitle" x="0" y="0" width="217" height="29"                               uuid="211c20f3-3a99-4086-9622-1f187165354d"/>                <textElement>                    <font size="22" isBold="false"/>                </textElement>                <text><![CDATA[user List]]></text>            </staticText>        </band>    </pageHeader>    <detail>        <band height="240" splitType="Immediate">            <frame>                <reportElement positionType="Float" x="11" y="60" width="551" height="51"                               uuid="1b0ed0d0-00ab-4545-a265-5359310553a3"/>                <staticText>                    <reportElement style="Column header" positionType="Float" x="2" y="10"                                   width="535" height="20" forecolor="#000000"                                   uuid="692020aa-377a-4e24-9e8a-6fe2f5e4c256"/>                    <textElement textAlignment="Left">                        <font isBold="false"/>                    </textElement>                    <text><![CDATA[addresses]]></text>                </staticText>                <textField isStretchWithOverflow="true" isBlankWhenNull="true">                    <reportElement style="Detail" positionType="Float" x="2" y="30"                                   width="535" height="18"                                   uuid="de745165-d51d-4c3e-b452-9d2dd29a7910"/>                    <textElement>                        <font size="14" isBold="true"/>                    </textElement>                    <textFieldExpression>                        <![CDATA[$F{addressLine1}+ "rn"                                 +(($F{addressLine2} == null ||                                     $F{addressLine2}.equals("")) ? ""                                      :( $F{addressLine2} + "rn"))                                  +(($F{addressLine3} == null ||                                     $F{addressLine3}.equals("") ) ? ""                                     :( $F{addressLine3} + "rn"))                                 +$F{city}+", "+$F{state}+" "+$F{zip}]]>                    </textFieldExpression>                </textField>            </frame>            <frame>                <reportElement positionType="Float" x="7" y="120" width="501" height="41"                               uuid="875b12fd-7979-4c87-821d-86762d098e58"/>                <staticText>                    <reportElement style="Column header" positionType="Float" x="166" y="0"                                   width="132" height="20" forecolor="#000000"                                   uuid="235d5a78-5f57-442d-b9b4-98544310b05e"/>                    <textElement textAlignment="Left">                        <font isBold="false"/>                    </textElement>                    <text><![CDATA[work phone]]></text>                </staticText>                <textField isStretchWithOverflow="true" isBlankWhenNull="true">                    <reportElement style="Detail" positionType="Float" x="316" y="20"                                   width="132" height="18"                                   uuid="78d03e5b-3671-4a70-bdb2-32ff6082f889"/>                    <textElement>                        <font size="14" isBold="true"/>                    </textElement>                    <textFieldExpression><![CDATA[$F{phone3}]]></textFieldExpression>                </textField>                <textField isStretchWithOverflow="true" isBlankWhenNull="true">                    <reportElement style="Detail" positionType="Float" x="6" y="20"                                   width="132" height="18"                                   uuid="51c11a83-f91c-454f-b96d-a1a9a412fb1f"/>                    <textElement>                        <font size="14" isBold="true"/>                    </textElement>                    <textFieldExpression><![CDATA[$F{phone1}]]></textFieldExpression>                </textField>                <staticText>                    <reportElement style="Column header" positionType="Float" x="316" y="0                                   width="132" height="20" forecolor="#000000"                                   uuid="3af16a5b-40a2-4c78-87c6-c9d733bdfefb"/>                    <textElement textAlignment="Left">                        <font isBold="false"/>                    </textElement>                    <text><![CDATA[mobile phone]]></text>                </staticText>                <staticText>                    <reportElement style="Column header" positionType="Float" x="6" y="0"                                   width="132" height="20" forecolor="#000000"                                   uuid="a0c91c41-4027-4546-83c4-3ff0c89427b9"/>                    <textElement textAlignment="Left">                        <font isBold="false"/>                    </textElement>                    <text><![CDATA[home phone]]></text>                </staticText>                <textField isStretchWithOverflow="true" isBlankWhenNull="true">                    <reportElement style="Detail" positionType="Float" x="166" y="20"                                   width="132" height="18"                                   uuid="3498a930-8baa-4ad8-b285-2426f23387fc"/>                    <textElement>                        <font size="14" isBold="true"/>                    </textElement>                    <textFieldExpression><![CDATA[$F{phone2}]]></textFieldExpression>                </textField>            </frame>            <staticText>                <reportElement style="Column header" positionType="Float" x="0" y="0"                               width="20" height="20" forecolor="#000000"                               uuid="d93c3bbe-31e1-4847-bf94-12d6811c5cd5"/>                <textElement textAlignment="Left">                    <font isBold="false"/>                </textElement>                <text><![CDATA[id]]></text>            </staticText>            <textField isStretchWithOverflow="true" isBlankWhenNull="true">                <reportElement style="Detail" positionType="Float" x="20" y="1"                               width="338" height="18"                               uuid="96575b26-9b88-49d3-9562-0b4461d15b0e"/>                <textElement>                    <font size="14" isBold="true"/>                </textElement>                <textFieldExpression><![CDATA[$F{id}]]></textFieldExpression>            </textField>            <staticText>                <reportElement style="Column header" positionType="Float" x="0" y="20"                               width="132" height="20" forecolor="#000000"                               uuid="36b072fa-c65b-4551-b905-a1d792131d86"/>                <textElement textAlignment="Left">                    <font isBold="false"/>                </textElement>                <text><![CDATA[first]]></text>            </staticText>            <textField isStretchWithOverflow="true" isBlankWhenNull="true">                <reportElement style="Detail" positionType="Float" x="0" y="41"                               width="132" height="18"                               uuid="55399657-e580-4058-91d1-76ce00e9baee"/>                <textElement>                    <font size="14" isBold="true"/>                </textElement>                <textFieldExpression><![CDATA[$F{first}]]></textFieldExpression>            </textField>            <staticText>                <reportElement style="Column header" positionType="Float" x="132" y="20"                               width="338" height="20" forecolor="#000000"                               uuid="8433d652-9225-4a48-9136-45753d7c107e"/>                <textElement textAlignment="Left">                    <font isBold="false"/>                </textElement>                <text><![CDATA[last]]></text>            </staticText>            <textField isStretchWithOverflow="true" isBlankWhenNull="true">                <reportElement style="Detail" positionType="Float" x="132" y="41" width="338"                               height="18" uuid="bd64961f-95da-4e43-b807-11fce0d232a2"/>                <textElement>                    <font size="14" isBold="true"/>                </textElement>                <textFieldExpression><![CDATA[$F{last}]]></textFieldExpression>            </textField>            <componentElement>                <reportElement positionType="Float" x="11" y="191" width="551" height="32"                               uuid="c48ef100-9a95-4575-b26d-a33d1b0f181d"/>                <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="Dataset1" uuid="a400cfcf-5036-4a20-8300-0e7bb012b315">                        <dataSourceExpression>                            <![CDATA[((net.sf.jasperreports.engine.data.JsonDataSource)$P{REPORT_DATA_SOURCE}).subDataSource("list")]]>                        </dataSourceExpression>                    </datasetRun>                    <jr:listContents height="32" width="551">                        <textField isStretchWithOverflow="true">                            <reportElement x="0" y="1" width="111" height="29"                                           uuid="d9b5cd97-a360-4a56-b7eb-0c3581aec90a"/>                            <textElement>                                <font fontName="Times New Roman" size="14" isBold="true"/>                            </textElement>                            <textFieldExpression>                                <![CDATA[$F{id}==null?"N/A":$F{id}]]>                            </textFieldExpression>                        </textField>                        <textField isStretchWithOverflow="true">                            <reportElement x="111" y="1" width="146" height="30"                                           uuid="671dc057-a397-42da-86d4-67c6aab32f41"/>                            <textElement>                                <font fontName="Times New Roman" size="14" isBold="true"/>                            </textElement>                            <textFieldExpression>                                <![CDATA[($F{date}==null?"N/A":new SimpleDateFormat("MM/dd/yyyy").format(new SimpleDateFormat("yyyy-mm-dd").parse($F{date})))]]>                            </textFieldExpression>                        </textField>                        <textField isStretchWithOverflow="true">                            <reportElement x="257" y="0" width="180" height="30"                                           uuid="73feabd7-f729-499b-8598-522a5a6734fc"/>                            <textElement>                                <font fontName="Times New Roman" size="14" isBold="true"/>                            </textElement>                            <textFieldExpression>                                <![CDATA[$F{status}==null? "N/A":$F{status}]]>                            </textFieldExpression>                        </textField>                    </jr:listContents>                </jr:list>            </componentElement>            <staticText>                <reportElement positionType="Float" x="11" y="171" width="110" height="21"                               isPrintWhenDetailOverflows="true"                               uuid="539a3c07-ae1c-469a-ba24-118757ce4b4b"/>                <textElement verticalAlignment="Middle">                    <font fontName="Times New Roman" size="14"/>                </textElement>                <text><![CDATA[access id]]></text>            </staticText>            <staticText>                <reportElement positionType="Float" x="121" y="171" width="147" height="21"                               isPrintWhenDetailOverflows="true"                               uuid="f60c2049-f67d-4ba6-9054-6ac87fb5bec6"/>                <textElement verticalAlignment="Middle">                    <font fontName="Times New Roman" size="14"/>                </textElement>                <text><![CDATA[date]]></text>            </staticText>            <staticText>                <reportElement positionType="Float" x="268" y="171" width="294" height="21"                               isPrintWhenDetailOverflows="true"                               uuid="3ca34485-1bf8-40ff-b952-a14541c3d03e"/>                <textElement verticalAlignment="Middle">                    <font fontName="Times New Roman" size="14"/>                </textElement>                <text><![CDATA[status]]></text>            </staticText>        </band>    </detail>    <pageFooter>        <band height="13" splitType="Stretch">            <frame>                <reportElement mode="Opaque" x="2" y="0" width="555" height="13"                               forecolor="#D0B48E" backcolor="#9DB1B8"                               uuid="bfdca178-800d-445c-9a31-bb616a00e8ce"/>                <textField evaluationTime="Report">                    <reportElement style="Column header" x="513" y="0" width="40" height="13"                                   forecolor="#FFFFFF"                                   uuid="2fba0f87-635e-476d-858f-d102b26146fe"/>                    <textElement verticalAlignment="Middle">                        <font size="10" isBold="false"/>                    </textElement>                    <textFieldExpression><![CDATA[" " + $V{PAGE_NUMBER}]]></textFieldExpression>                </textField>                <textField>                    <reportElement style="Column header" mode="Transparent" x="433" y="0"                                   width="80" height="13" forecolor="#FFFFFF"                                   uuid="e454d23d-bcfc-4c79-a399-0ef520a3150a"/>                    <textElement textAlignment="Right" verticalAlignment="Middle">                        <font size="10" isBold="false"/>                    </textElement>                    <textFieldExpression>                        <![CDATA["Page "+$V{PAGE_NUMBER}+" of"]]>                    </textFieldExpression>                </textField>                <textField pattern="EEEEE dd MMMMM yyyy">                    <reportElement style="Column header" x="2" y="0" width="197" height="13"                                   forecolor="#FFFFFF"                                   uuid="14d8de1e-8695-4078-a67f-0e69172574d5"/>                    <textElement verticalAlignment="Middle">                        <font size="10" isBold="false"/>                    </textElement>                    <textFieldExpression>                        <![CDATA[new java.util.Date()]]>                    </textFieldExpression>                </textField>            </frame>        </band>    </pageFooter>    <summary>        <band splitType="Stretch"/>    </summary></jasperReport>[/code]

data file (json)

{    "user": [                {                    "id": 1,                    "first": "Abc",                    "last": "Def",                    "addresses":                    {                    "addressType": "HOME",                    "addressLine1": "1 Abc Lane",                    "addressLine2": "Apt 123",                    "addressLine3": "",                    "city": "Anytown",                    "state": "XX",                    "zip": "99999"                    },                    "phone":                    {                    "telephone1": "123 456 7890",                    "telephone2": "123 456 7890",                    "telephone3": "123 456 7890"                    },                    "list":[                        {                        "id": 645334,                        "date": "2016-06-07T04:00:00.000Z",                        "status": "Active"                        },                        {                        "id": 645334,                        "date": "2016-06-07T04:00:00.000Z",                        "status": ""                        }                    ]                                },                {                    "id": 2,                    "first": "Ijk",                    "last": "Lmn",                    "addresses":                    {                    "addressType": "HOME",                    "addressLine1": "1 Abc Lane",                    "addressLine2": "Apt 123",                    "addressLine3": "",                    "city": "Anytown",                    "state": "XX",                    "zip": "99999"                    },                    "phone":                    {                    "telephone1": "123 456 7890",                    "telephone2": "123 456 7890",                    "telephone3": "123 456 7890"                    }                                    }        ]}[/code]

 

Link to comment
Share on other sites

  • Replies 5
  • Created
  • Last Reply

Top Posters In This Topic

Hi Hozawa,

Thank you for your advice. I made a little change and it is working. it displays "N/A" when text field is empty.

($F{status}==null || $F{status}.length() == 0) ? "N/A":$F{status}

but I still could not display  the message "no data available" below the column headers when there is no data return in the list.

Your help would be greatly appreciated.

 

Link to comment
Share on other sites

  • 2 years later...

Did you ever resolve the "no data available" issue?  I'm running into the same issue but I can't figure it out.  Essentially my list is blank, but I would like to show something "No Data Available" or "N/A".  The answer that was given only works if some of the dataset has blanks, not if there is no dataset returned.

Link to comment
Share on other sites

  • 4 months later...

You can use "No Data" band to display your message if report main data source query produces empty dataset. In the latest 7.5.0 release, you can also display no data message for report sub dataset. For exmaple, you can display no data message in your report table element no data section in 7.5.0 version which you were not able to do in the past. 

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

×
×
  • Create New...