2012-07-14 82 views
1

我試圖隱藏我已經放置在頁面頁眉帶中的文本框。字段值由運行時傳入報表的幾個參數決定。實質上,我希望字段在參數值爲空(或其中一些爲空)時爲空或隱藏。如何根據幾個參數的值隱藏文本字段?

當我執行我的代碼時,我得到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> 

回答

0

你這裏有幾個問題:

1)您設置了默認calue的參數date_startdate_end。這意味着他們永遠不會爲空。 (如果你顯式傳入參數的空值,這可能會被覆蓋,但我不確定是否誠實)。最好的辦法是不要爲這兩個參數設置默認值。

2)如果你想隱藏字段,那麼我會在字段上表達時使用打印。例如日期範圍文本框最終會看起來像:

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

我跑這個修改報告使用空數據源,並不同的參數值,它似乎工作如何你想要的。

1

基本上我希望字段爲空或時隱時現的參數值是空的(或其中有些是空)

爲此,我想打印時,表達會很方便。假設param1是你的參數,你可以添加像(!$ P {param1} == null)。只有當參數有一個值時,該字段纔會顯示。 最重要的是,這在指定默認值時不起作用。因爲在指定的默認值下,參數不能爲空或爲空。

相關問題