【问题标题】:Jasper Conditional Style with parameter带参数的 Jasper 条件样式
【发布时间】:2017-06-23 21:49:21
【问题描述】:

我想在我的帖子中设置样式,但它不起作用,我有一个错误:

 1. Parameter not found : choixImpression

但问题是我创建了变量,如果我将它添加到文本字段中,它将显示但条件样式不起作用。

我的jrxml

<jasperReport ...>
    <style name="Table 1_TH" mode="Opaque" backcolor="#2E6F98">
        <box>
            <pen lineWidth="0.5" lineColor="#000000"/>
        </box>
        <conditionalStyle>
            <conditionExpression><![CDATA[new Boolean($V{choixImpression}.toString().equals("MODERNE_NOIR_ET_BLANC"))]]></conditionExpression>
            <style backcolor="#99FF99"/>
        </conditionalStyle>
    </style>
    <parameter name="choixImpression" class="java.lang.String"/>
    <variable name="choixImpression" class="java.lang.String">
        <variableExpression><![CDATA[$P{choixImpression}]]></variableExpression>
    </variable>
    <title>
        <band height="198" splitType="Stretch">
            <textField>
                <reportElement style="Table 1_TH" mode="Opaque" x="201" y="63" width="100" height="20"/>
                <textElement/>
                <textFieldExpression class="java.lang.String"><![CDATA[$F{field}]]></textFieldExpression>
            </textField>
        </band>
    </title>
</jasperReport>

【问题讨论】:

  • 尝试在报告的标题处添加&lt;property name="net.sf.jasperreports.style.evaluation.time.enabled" value="true"/&gt;。问题描述here
  • 顺便说一句,在变量表达式中使用参数的原因是什么?
  • 我仍然有错误,它没有改变任何东西

标签: jasper-reports


【解决方案1】:

您引用的是参数而不是变量

如果确实应该使用变量,请使用 $V{choixImpression} 而不是 $P{choixImpression}

编辑

你有一个括号问题...

您的代码尝试获取StringBoolean 值,然后将此Boolean 值与指定的String 常量进行比较:

<conditionExpression><![CDATA[new Boolean($P{choixImpression}.toString()).equals("MODERNE_NOIR_ET_BLANC")]]></conditionExpression>

应该尝试这样的事情:

<conditionExpression><![CDATA["MODERNE_NOIR_ET_BLANC".equals($P{choixImpression})]]></conditionExpression>

编辑

我不知道,但是事情的顺序重要吗?

您的参数在表达式之后声明...

【讨论】:

  • @dadadaa 此外,如果您使用支持自动装箱/拆箱 Java 的版本 - 您可以删除布尔包装器
  • Boolean.valueOf() - 没有必要(使用自动装箱/拆箱)
  • Your parameters are declared after the expression... - JR 模板没问题
  • 返回参数,JRXML无效
猜你喜欢
  • 2018-10-16
  • 1970-01-01
  • 2020-05-11
  • 1970-01-01
  • 1970-01-01
  • 2013-10-22
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多