2

我试图隐藏我放置在页眉带中的文本字段。字段值由运行报告时传递给报告的几个参数确定。本质上,当参数值为空(或其中一些为空)时,我希望该字段为空白或隐藏。

当我执行我的代码时,我得到incompatable operand int and integer. 我已附上以下报告:

<?xml version="1.0" encoding="UTF-8"  ?>
<!-- Created with iReport - A designer for JasperReports -->
<!DOCTYPE jasperReport PUBLIC "//JasperReports//DTD Report Design//EN" "http://jasperreports.sourceforge.net/dtds/jasperreport.dtd">
<jasperReport
         name="Date_Register"
         columnCount="1"
         printOrder="Vertical"
         orientation="Landscape"
         pageWidth="842"
         pageHeight="595"
         columnWidth="802"
         columnSpacing="0"
         leftMargin="20"
         rightMargin="20"
         topMargin="20"
         bottomMargin="20"
         whenNoDataType="AllSectionsNoDetail"
         isTitleNewPage="false"
         isSummaryNewPage="false">
    <property name="ireport.zoom" value="1.0" />
    <property name="ireport.x" value="95" />
    <property name="ireport.y" value="3" />
    <property name="ireport.scriptlethandling" value="0" />
    <property name="ireport.encoding" value="UTF-8" />
    <import value="java.util.*" />
    <import value="net.sf.jasperreports.engine.*" />
    <import value="net.sf.jasperreports.engine.data.*" />
    <import value="com.google.common.base.*" />

    <parameter name="date_start" isForPrompting="true" class="java.sql.Timestamp">
        <defaultValueExpression ><![CDATA[new java.sql.Timestamp(0)]]></defaultValueExpression>
    </parameter>
    <parameter name="date_end" isForPrompting="true" class="java.sql.Timestamp">
        <defaultValueExpression ><![CDATA[new java.sql.Timestamp(System.currentTimeMillis())]]></defaultValueExpression>
    </parameter>
    <parameter name="lookup_month" isForPrompting="true" class="java.lang.Integer">
        <defaultValueExpression ><![CDATA[new Integer(-1)]]></defaultValueExpression>
    </parameter>
    <parameter name="lookup_year" isForPrompting="true" class="java.lang.Integer">
        <defaultValueExpression ><![CDATA[new Integer(-1)]]></defaultValueExpression>
    </parameter>
    <parameter name="lookup_quarter" isForPrompting="true" class="java.lang.Integer">
        <defaultValueExpression ><![CDATA[new Integer(-1)]]></defaultValueExpression>
    </parameter>
    <parameter name="lookup_weeks" isForPrompting="true" class="java.lang.Integer">
        <defaultValueExpression ><![CDATA[new Integer(-1)]]></defaultValueExpression>
    </parameter>
    <parameter name="woman_status" isForPrompting="true" class="java.lang.String">
        <defaultValueExpression ><![CDATA["N"]]></defaultValueExpression>
    </parameter>
    <parameter name="industry_group" isForPrompting="true" class="java.lang.Integer">
        <defaultValueExpression ><![CDATA[new Integer(-1)]]></defaultValueExpression>
    </parameter>
    <parameter name="equity_structure" isForPrompting="true" class="java.lang.String">
        <defaultValueExpression ><![CDATA["BUMIPUTERA"]]></defaultValueExpression>
    </parameter>
    <queryString><![CDATA[select distinct convert(varchar(10),a.entered,103) as daterange,
a.org_id,
a.name,
a.business_name_two,
a.organization_type,
c.description as companygroup,lead,
a.industry_temp_code,
b.description,
a.equity_structure,
case when a.sic_description = 1 then 'BUMIPUTERA'
     when a.sic_description = 2 then 'NON BUMIPUTERA' end race,
convert(varchar(10),a.entered,103) as
dateregister
from organization a
left join lookup_industry b on a.industry_temp_code = b.code
left join lookup_company_group c on c.code = a.company_group
left join ticket d on d.org_id = a.org_id
left join lookup_month lm on lm.code =a.operation_date 
left join lookup_weeks lw on lw.code =a.operation_date
left join lookup_quarter lq on lq.code =a.operation_date
left join lookup_year ly on ly.code =a.operation_date
where
a.equity_structure is not null
and
business_name_two is not null
and
c.description is not null
and
((a.business_name_two = $P{woman_status}) or ($P{woman_status} = ' '))
and
((a.industry_temp_code = $P{industry_group}) or($P{industry_group} = -1))
and
(((case when a.sic_description = 1 then 'BUMIPUTERA'
     when a.sic_description = 2 then 'NON BUMIPUTERA' end ) = $P{equity_structure}) or ($P{equity_structure} = ' '))
and
((a.operation_date BETWEEN convert(datetime,$P{date_start},103) AND convert(datetime,$P{date_end},103))
or (convert(datetime,$P{date_start},103) =' ' AND convert(datetime,$P{date_end},103) = ' '))

AND
((lm.code = $P{lookup_month}) or ($P{lookup_month} = -1)) 
AND
((ly.code = $P{lookup_year}) or ($P{lookup_year} = -1))
AND
((lq.code = $P{lookup_quarter}) or ($P{lookup_quarter} = -1))
AND
((lw.code = $P{lookup_weeks}) or ($P{lookup_weeks} = -1))]]></queryString>

    <field name="daterange" class="java.lang.String"/>
    <field name="org_id" class="java.lang.Integer"/>
    <field name="name" class="java.lang.String"/>
    <field name="business_name_two" class="java.lang.String"/>
    <field name="organization_type" class="java.lang.String"/>
    <field name="companygroup" class="java.lang.String"/>
    <field name="lead" class="java.lang.String"/>
    <field name="industry_temp_code" class="java.lang.Integer"/>
    <field name="description" class="java.lang.String"/>
    <field name="equity_structure" class="java.lang.String"/>
    <field name="race" class="java.lang.String"/>
    <field name="dateregister" class="java.lang.String"/>

        <background>
            <band height="0"  isSplitAllowed="true" >
            </band>
        </background>
        <title>
            <band height="0"  isSplitAllowed="true" >
            </band>
        </title>
        <pageHeader>
            <band height="187"  isSplitAllowed="true" >
                <staticText>
                    <reportElement
                        x="0"
                        y="0"
                        width="802"
                        height="18"
                        key="staticText"/>
                    <box topBorder="None" topBorderColor="#000000" leftBorder="None" leftBorderColor="#000000" rightBorder="None" rightBorderColor="#000000" bottomBorder="None" bottomBorderColor="#000000"/>
                    <textElement textAlignment="Center">
                        <font fontName="SansSerif" size="12" isBold="true"/>
                    </textElement>
                <text><![CDATA[Date Registered
]]></text>
                </staticText>
                <textField isStretchWithOverflow="true" pattern="" isBlankWhenNull="true" evaluationTime="Now" hyperlinkType="None"  hyperlinkTarget="Self" >
                    <reportElement
                        x="0"
                        y="54"
                        width="802"
                        height="42"
                        key="textField-1"
                        isRemoveLineWhenBlank="true"/>
                    <box topBorder="None" topBorderColor="#000000" leftBorder="None" leftBorderColor="#000000" rightBorder="None" rightBorderColor="#000000" bottomBorder="None" bottomBorderColor="#000000"/>
                    <textElement textAlignment="Left" verticalAlignment="Top" rotation="None" isStyledText="true" lineSpacing="1_1_2">
                        <font size="11" isBold="true"/>
                    </textElement>
                <textFieldExpression   class="java.lang.String"><![CDATA[($P{date_start}!= null) && ($P{date_end}!=null) && ($P{lookup_month}!= -1) && ($P{lookup_year}!=-1)&& ($P{lookup_quarter}!= -1) && ($P{lookup_weeks}!=-1) ? "Date Ticket Created From : " + new SimpleDateFormat("dd/MM/yyyy").format($P{date_start}) +"\n" + "Date Ticket Created to : " + new SimpleDateFormat("dd/MM/yyyy").format($P{date_end})
: null]]></textFieldExpression>
                </textField>
                <textField isStretchWithOverflow="true" isBlankWhenNull="true" evaluationTime="Now" hyperlinkType="None"  hyperlinkTarget="Self" >
                    <reportElement
                        x="0"
                        y="20"
                        width="802"
                        height="35"
                        key="textField-2"
                        isRemoveLineWhenBlank="true"/>
                    <box topBorder="None" topBorderColor="#000000" leftBorder="None" leftBorderColor="#000000" rightBorder="None" rightBorderColor="#000000" bottomBorder="None" bottomBorderColor="#000000"/>
                    <textElement textAlignment="Center" verticalAlignment="Top" rotation="None" lineSpacing="Single">
                        <font size="12" isBold="true"/>
                    </textElement>
                <textFieldExpression   class="java.lang.String"><![CDATA[($P{date_start}!= null) && ($P{date_end}!=null) && ($P{lookup_month}== -1) && ($P{lookup_year}==-1)&& ($P{lookup_quarter}== -1) && ($P{lookup_weeks}==-1)? " From ( " + new SimpleDateFormat("dd/MM/yyyy").format($P{date_start}) + " - " + new SimpleDateFormat("dd/MM/yyyy").format($P{date_end}) + " )"
:($P{date_start}== null) && ($P{date_end}==null) && ($P{lookup_month}!= -1) && ($P{lookup_year}!=-1)&& ($P{lookup_quarter}== -1) && ($P{lookup_weeks}!=-1)? "For week " + $P{lookup_weeks} +" "+ $P{lookup_month} +" "+ $P{lookup_year}
:($P{date_start}== null) && ($P{date_end}==null) && ($P{lookup_month}!= -1) && ($P{lookup_year}!=-1)&& ($P{lookup_quarter}== -1) && ($P{lookup_weeks}==-1)? "For monthly " +$P{lookup_month} +" "+ $P{lookup_year}
:($P{date_start}== null) && ($P{date_end}==null) && ($P{lookup_month}== -1) && ($P{lookup_year}!=-1)&& ($P{lookup_quarter}!= -1) && ($P{lookup_weeks}==-1)? "For Quarter " + $P{lookup_quarter} +" "+$P{lookup_year}
:($P{date_start}== null) && ($P{date_end}==null) && ($P{lookup_month}== -1) && ($P{lookup_year}!=-1)&& ($P{lookup_quarter}== -1) && ($P{lookup_weeks}==-1)? "For Year " + $P{lookup_year}
: $P{lookup_year}]]></textFieldExpression>
                </textField>
            </band>
        </pageHeader>
        <columnHeader>
            <band height="0"  isSplitAllowed="true" >
            </band>
        </columnHeader>
        <detail>
            <band height="0"  isSplitAllowed="true" >
            </band>
        </detail>
        <columnFooter>
            <band height="0"  isSplitAllowed="true" >
            </band>
        </columnFooter>
        <pageFooter>
            <band height="0"  isSplitAllowed="true" >
            </band>
        </pageFooter>
        <summary>
            <band height="0"  isSplitAllowed="true" >
            </band>
        </summary>
</jasperReport>
4

2 回答 2

2

本质上,当参数值为空(或其中一些为空)时,我希望该字段为空白或隐藏

为此,我想 Print when Expression 会非常方便。假设 param1 是您的参数,您可以添加类似 (!$P{param1}==null) 的内容。只有当参数有值时,才会显示该字段。最重要的是,当指定默认值时,这将不起作用。因为在指定默认值的情况下,参数永远不能为空或 null。

于 2012-07-20T11:44:02.060 回答
0

您在这里有几个问题:

1)您确实为参数设置了默认值,date_start并且date_end。这意味着它们永远不会为空。(如果您明确地为参数传入一个空值,这可能会被覆盖,但我不确定是否诚实)。您最好不要为这两个参数设置默认值。

2)如果您想隐藏字段,那么我会在字段上使用 print when 表达式。例如,您的日期范围文本字段最终看起来像:

<textField isStretchWithOverflow="true" pattern="" isBlankWhenNull="true">
  <reportElement uuid="9bcc0870-adaf-4bb3-bd4d-40bf120a0d1f" key="textField-1" x="0" y="54" width="802" height="42" isRemoveLineWhenBlank="true">
    <printWhenExpression><![CDATA[($P{date_start}!= null) && ($P{date_end}!=null)]]></printWhenExpression>
  </reportElement>
  <box>
    <topPen lineWidth="0.0" lineStyle="Solid" lineColor="#000000"/>
    <leftPen lineWidth="0.0" lineStyle="Solid" lineColor="#000000"/>
    <bottomPen lineWidth="0.0" lineStyle="Solid" lineColor="#000000"/>
    <rightPen lineWidth="0.0" lineStyle="Solid" lineColor="#000000"/>
  </box>
  <textElement textAlignment="Left" verticalAlignment="Top" rotation="None" markup="styled">
    <font size="11" isBold="true"/>
    <paragraph lineSpacing="1_1_2"/>
  </textElement>
  <textFieldExpression><![CDATA["Date Ticket Created From : " + new SimpleDateFormat("dd/MM/yyyy").format($P{date_start}) +"\n" + "Date Ticket Created to : " + new SimpleDateFormat("dd/MM/yyyy").format($P{date_end})]]></textFieldExpression>
</textField>

我也会为您的顶级文本字段做类似的事情:

<textField isStretchWithOverflow="true" isBlankWhenNull="true">
  <reportElement uuid="37137d13-5d49-40fb-8627-0ffdfc555ef4" key="textField-2" x="0" y="20" width="802" height="35" isRemoveLineWhenBlank="true">
    <printWhenExpression><![CDATA[(($P{date_start}!= null) && ($P{date_end}!=null)) || ($P{lookup_year}!=-1)]]></printWhenExpression>
  </reportElement>
  <box>
    <topPen lineWidth="0.0" lineStyle="Solid" lineColor="#000000"/>
    <leftPen lineWidth="0.0" lineStyle="Solid" lineColor="#000000"/>
    <bottomPen lineWidth="0.0" lineStyle="Solid" lineColor="#000000"/>
    <rightPen lineWidth="0.0" lineStyle="Solid" lineColor="#000000"/>
  </box>
  <textElement textAlignment="Center" verticalAlignment="Top" rotation="None">
    <font size="12" isBold="true"/>
    <paragraph lineSpacing="Single"/>
  </textElement>
  <textFieldExpression><![CDATA[($P{date_start}!= null) && ($P{date_end}!=null) ? " From ( " + new SimpleDateFormat("dd/MM/yyyy").format($P{date_start}) + " - " + new SimpleDateFormat("dd/MM/yyyy").format($P{date_end}) + " )"
  : ($P{lookup_month}!= -1) && ($P{lookup_year}!=-1) &&  ($P{lookup_weeks}!=-1) ? "For week " + $P{lookup_weeks} +" "+ $P{lookup_month} +" "+ $P{lookup_year}
  : ($P{lookup_month}!= -1) && ($P{lookup_year}!=-1) ? "For monthly " +$P{lookup_month} +" "+ $P{lookup_year}
  : ($P{lookup_year}!=-1) && ($P{lookup_quarter}!=-1) ? "For Quarter " + $P{lookup_quarter} +" "+$P{lookup_year}
  : ($P{lookup_year}!=-1) ? "For Year " + $P{lookup_year}
  : null]]></textFieldExpression>
</textField>

我使用空数据源和不同的参数值运行了带有此修改的报告,它似乎可以按照您的意愿工作。

于 2012-07-17T17:53:07.180 回答