条件样式的麻烦

时间:2013-07-10 15:52:24

标签: styles jasper-reports

感谢大家,感谢Alex K,我得到了原因。这可能是错误的 ireport 3.0。 外部样式标记不应包含color属性。 我删除它,它运作良好。

=============================================== ================================= 我在使用 JasperReports 的报告中遇到了关于条件样式表达的问题。 iReport的版本是3.0

我刚发现布尔表达式根本不起作用。


条件样式:

<style 
    name="old"
    mode="Opaque"
    **forecolor="#990033"**
>

    <conditionalStyle>
        <conditionExpression><![CDATA[$F{age}.intValue()>60?new Boolean(true):new Boolean(false)]]></conditionExpression>
        <style 
            name="old"
            isDefault="false"
            mode="Opaque"
            forecolor="#990033"
        >
        </style>
    </conditionalStyle>
</style>

文本字段表达式:

<textField isStretchWithOverflow="false" pattern="" isBlankWhenNull="false" evaluationTime="Now" hyperlinkType="None"  hyperlinkTarget="Self" >
                <reportElement
                    style="old"
                    x="315"
                    y="0"
                    width="78"
                    height="14"
                    key="textField-3"/>
                <box></box>
                <textElement>
                    <font/>
                </textElement>
            <textFieldExpression   class="java.lang.Integer"><![CDATA[$F{age}]]></textFieldExpression>
            </textField>

结果是,即使年龄小于60岁,所有年龄都会变红;

1 个答案:

答案 0 :(得分:0)

感谢大家,感谢Alex K,我得到了原因。这可能是ireport 3.0的错误。外部样式标记不应包含color属性。我删除它,它运作良好。 那是 : 由ireport生成的xml代码是

<style 
    name="old"
    mode="Opaque"
    forecolor="#990033"
>

    <conditionalStyle>
        <conditionExpression><![CDATA[$F{age}.intValue()>60?new Boolean(true):new Boolean(false)]]></conditionExpression>
        <style 
            name="old"
            isDefault="false"
            mode="Opaque"
            forecolor="#990033"
        >
        </style>
    </conditionalStyle>
</style>

这样风格已经有效。我删除外部样式标记中的属性集。 所以最终的xml代码运行良好如下:

<style 
    name="old"
    mode="Opaque"   
>

    <conditionalStyle>
        <conditionExpression><![CDATA[$F{age}.intValue()>60?new Boolean(true):new Boolean(false)]]></conditionExpression>
        <style 
            name="old"
            isDefault="false"
            mode="Opaque"
            forecolor="#990033"
        >
        </style>
    </conditionalStyle>
</style>