Jump to content
JasperReports Library 7.0 is now available ×

Remove Label when field is empty


camnott

Recommended Posts

Hello,

I have two fields, $F{UPCOMINGEVENTS} and $F{ACCOMPLISHMENTS}. Each of these fields have a label, which is in the same group. The fields are set to Blank When Null, which works fine.

I am trying to find a way to also remove the labels when the field is blank. I found a response that was like this $F{UPCOMINGEVENTS}==null?"":$F{LabelName}  this did not work as it could not resolve the label as a field.

Any thoughts?

                <textField>                    <reportElement positionType="Float" x="440" y="82" width="120" height="18" uuid="f2f0234a-624f-4651-a768-f7532717483d"/>                    <textElement>                        <font isBold="true"/>                    </textElement>                    <textFieldExpression><![CDATA["Upcoming Activities:"]]></textFieldExpression>                </textField>                <textField isStretchWithOverflow="true" isBlankWhenNull="true">                    <reportElement positionType="Float" x="440" y="100" width="340" height="40" uuid="7f192789-debc-4da5-9836-da64a626b9d2">                        <property name="local_mesure_unity" value="inch"/>                    </reportElement>                    <box padding="0">                        <topPen lineWidth="0.0" lineStyle="Solid" lineColor="#000000"/>                        <leftPen lineWidth="0.0" lineStyle="Solid" lineColor="#000000"/>                        <bottomPen lineWidth="0.0" lineStyle="Solid" lineColor="#000000"/>                        <rightPen lineWidth="0.0" lineStyle="Solid" lineColor="#000000"/>                    </box>                    <textFieldExpression><![CDATA[$F{UPCOMINGEVENTS}]]></textFieldExpression>                </textField>[/code]

 

Link to comment
Share on other sites

  • Replies 1
  • Created
  • Last Reply

Top Posters In This Topic

Popular Days

Top Posters In This Topic

I would do it this way, if using Oracle. Its all about writing sql queries and manipulating data. 

In this query, I'm trying to find if the SQL column has any values in it or not and based on that display another column (count(hidden) over()) called as cnt. 

On the report, I'm hiding or displaying the label based on this cnt value. 

<?xml version="1.0" encoding="UTF-8"?><!-- Created with Jaspersoft Studio version 6.4.2.final using JasperReports Library version 6.4.1  --><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="hiddenColumns" pageWidth="595" pageHeight="842" columnWidth="555" leftMargin="20" rightMargin="20" topMargin="20" bottomMargin="20" uuid="f58fcefb-99f3-4b9b-82f8-ea7e2def8065">    <property name="com.jaspersoft.studio.data.sql.tables" value=""/>    <queryString>        <![CDATA[select ID, value, hidden, count(hidden) over() cnt  from (select 1 as ID, '1value' as value, null as hidden          from dual        union all        select 2 as ID, '2value' as value, 1 as hidden          from dual        union all        select 3 as ID, '3value' as value, null as hidden          from dual        union all        select 4 as ID, '4value' as value, null as hidden          from dual)]]>    </queryString>    <field name="ID" class="java.math.BigDecimal"/>    <field name="VALUE" class="java.lang.String"/>    <field name="HIDDEN" class="java.math.BigDecimal"/>    <field name="CNT" class="java.math.BigDecimal"/>    <background>        <band splitType="Stretch"/>    </background>    <columnHeader>        <band height="20" splitType="Stretch">            <staticText>                <reportElement x="0" y="0" width="80" height="20" uuid="805c2f8d-cdca-4595-8218-8570b40401d2"/>                <text><![CDATA[iD]]></text>            </staticText>            <staticText>                <reportElement x="80" y="0" width="100" height="20" uuid="39b36d26-e2ec-4ea7-aa88-893707be4378"/>                <text><![CDATA[VALUE]]></text>            </staticText>            <textField>                <reportElement x="180" y="0" width="185" height="20" uuid="8a5676a9-0105-42b9-95bf-c6eb0cca04c7"/>                <textFieldExpression><![CDATA[$F{CNT}.intValue() >= 0 ? "HIDDEN FIELD" : ""]]></textFieldExpression>            </textField>        </band>    </columnHeader>    <detail>        <band height="20" splitType="Stretch">            <textField>                <reportElement x="0" y="0" width="80" height="20" uuid="38185a27-39e0-4d5f-b8ed-9883b9f4cc8b">                    <property name="com.jaspersoft.studio.unit.height" value="pixel"/>                </reportElement>                <textFieldExpression><![CDATA[$F{ID}]]></textFieldExpression>            </textField>            <textField>                <reportElement x="80" y="0" width="100" height="20" uuid="1b58f194-7829-4f66-8585-737366362d24"/>                <textFieldExpression><![CDATA[$F{VALUE}]]></textFieldExpression>            </textField>            <textField isStretchWithOverflow="true" isBlankWhenNull="true">                <reportElement x="180" y="0" width="185" height="20" uuid="f9dbd4e9-1c65-4145-9e25-06ba9aeabde4"/>                <textFieldExpression><![CDATA[$F{HIDDEN}]]></textFieldExpression>            </textField>        </band>    </detail></jasperReport>[/code]

In order to hide the column entirely, try changing the 1 as hidden to null as hidden on the 2nd row of the SQL. 

 

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...