Image 基于条件显示图像
下面的代码不起作用,我得到一个错误Image 基于条件显示图像,image,jasper-reports,conditional-statements,Image,Jasper Reports,Conditional Statements,下面的代码不起作用,我得到一个错误 <image> <reportElement x="42" y="101" width="22" height="23"/> <printWhenExpression>($F{booleanConditon} ? <![CDATA[$P{path} + "checkBox.png"]] : <![CDATA[$P{path} + "unCheckBox.png"]]>)</printWhenE
<image>
<reportElement x="42" y="101" width="22" height="23"/>
<printWhenExpression>($F{booleanConditon} ? <![CDATA[$P{path} + "checkBox.png"]] : <![CDATA[$P{path} + "unCheckBox.png"]]>)</printWhenExpression>
</image>
您需要在
中标记表达式的全部,以便xml解析器将其纯粹解释为文本数据,表达式的计算将由jasper报告引擎完成
<printWhenExpression><![CDATA[($F{booleanConditon} ? $P{path} + "checkBox.png" : $P{path} + "unCheckBox.png")]]></printWhenExpression>
因此,评估过程首先解析xml(sax解析器),然后解析表达式(jasper report engine)问题是xml无效。 元素
printWheenexpression
不能是image
的直接子元素。它应该是reportElement
的子元素
例如:
<image>
<reportElement x="42" y="101" width="22" height="23">
<printWhenExpression>($F{booleanConditon} ? <![CDATA[$P{path} + "checkBox.png"]] : <![CDATA[$P{path} + "unCheckBox.png"]]>)</printWhenExpression>
</reportElement>
</image>
($F{booleanConditon}?)
我也面临同样的问题。解决办法如下。你可以拍一张照片,但是
我有两张图片checked.png和unchecked.png。
我已经对数据库进行了查询,并获取了字段“checkAsIsFlag”的值。此字段包含“Y”(选中)或“N”(未选中)作为文本值。如果checkAsIsFlag='Y',我将显示checked.png图像;如果checkAsIsFlag='N',我将显示unchecked.png图像
我把两张图片都放在了设计页面上,一张在另一张的上面(以像素为单位,位置相同)。在“表达式打印时打印”字段中,检查参考图像
简短的源代码如下:
<image>
<reportElement x="30" y="7" width="25" height="25" uuid="afe9a678-28a4-40d2-bc61-82b49fb904d9">
<property name="com.jaspersoft.studio.unit.width" value="pixel"/>
<property name="com.jaspersoft.studio.unit.height" value="pixel"/>
<property name="com.jaspersoft.studio.unit.x" value="pixel"/>
<printWhenExpression><![CDATA[$F{checkasisflag}.equals("Y")]]></printWhenExpression>
</reportElement>
<imageExpression><![CDATA["http://localhost:8080/studentreport/images/checked.png"]]></imageExpression>
</image>
<image>
<reportElement x="30" y="7" width="25" height="25" uuid="a993026c-430e-4f56-9531-3baaa0de11f4">
<property name="com.jaspersoft.studio.unit.width" value="pixel"/>
<property name="com.jaspersoft.studio.unit.height" value="pixel"/>
<property name="com.jaspersoft.studio.unit.x" value="pixel"/>
<property name="com.jaspersoft.studio.unit.y" value="pixel"/>
<printWhenExpression><![CDATA[$F{checkasisflag}.equals("N")]]></printWhenExpression>
</reportElement>
<imageExpression><![CDATA["http://localhost:8080/studentreport/images/unchecked.png"]]></imageExpression>
</image>
使用图像表达式,如下所示 例如:
<imageExpression><![CDATA[$V{PAGE_NUMBER}==1 ? "img/watermark_firstpage.png" : "img/watermark_otherpage.png"]]></imageExpression>
<imageExpression><![CDATA[$V{PAGE_NUMBER}==1 ? "img/watermark_firstpage.png" : "img/watermark_otherpage.png"]]></imageExpression>