2010-05-12 31 views
7

我想有一對TextFields取決於一個值。並且「y」值應該根據空白空間進行調整。如何在JasperReports中使用條件TextField?

當值爲"0"我想隱藏TextField。

I.e.我想隱藏staticTexttextField如果參數red等於"0"和具有藍色的值向上移動時,在下面的JRXML碼:

<staticText> 
    <reportElement x="100" y="30" width="100" height="30"/> 
    <text><![CDATA[Red items:]]></text> 
    </staticText> 
    <textField> 
    <reportElement x="200" y="30" width="40" height="30"/> 
    <textFieldExpression> 
     <![CDATA[$P{red}]]> 
    </textFieldExpression> 
    </textField> 

    <staticText> 
    <reportElement x="100" y="60" width="100" height="30"/> 
    <text><![CDATA[Blue items:]]></text> 
    </staticText> 
    <textField> 
    <reportElement x="200" y="60" width="40" height="30"/> 
    <textFieldExpression> 
     <![CDATA[$P{blue}]]> 
    </textFieldExpression> 
    </textField> 

輸出的實施例:

//if blue = 3 and red = 2 if blue = 3 and red = 0 if blue = 0 and red = 2 
    Red items: 2    Blue items: 3    Red items: 2 
    Blue items: 3  

這些TextFields將放置在我的報告結尾處。我怎樣才能做到這一點?

回答

11
<reportElement ...> 
    <printWhenExpression><![CDATA[$P{red} == 0]]></printWhenExpression> 
</reportElement> 

您可以使用iReport用愉快的用戶界面進行修改。

+1

領域的空選項,不適合我的工作使空白,我得到這個錯誤:「)」預期 值=(java.lang.Boolean中)($ {紅== 0}); // $ JR_EXPR_ID = 12 $ – Jonas 2010-05-12 18:04:32

+0

我現在已經擴展了我的問題。我不知道這是否可能在JasperReports中。 – Jonas 2010-05-12 18:19:31

+0

好吧,只需將''添加到其他字段中,並使用適當的條件 – Bozho 2010-05-13 06:14:30

1

這樣,不,我不確定這是可能的。

有一個選項叫Remove Link When Blank,但它只適用於如果你想刪除整條線。在這裏你想刪除特定列中的一行。

在這種情況下,我會建議使用crosstab或CrossTables功能。

給列組X的值(假設X爲列號) 並給予行集團的色域值,從這裏可以動態地更改標籤,像這樣:

$F{color}==null?"": ($F{color}.equals("RED")?"Red Items":"Blue Items") 
0

你可以使用這樣

Declare RED as [class="java.lang.Number"] 

在打印過程中

$P{red}.intValue() == 0 ? null : $P{red}.intValue() 

當使用

textField isBlankWhenNull="true">    
<reportElement x="100" y="30" width="100" height="30" isRemoveLineWhenBlank="true"/> 
相關問題