【发布时间】:2012-05-21 22:33:24
【问题描述】:
如何将 if-else 表达式从 JasperReports 4.x 语法迁移到 JasperReports 2.x 语法?
这是我的代码:
<?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="convertString"
columnCount="1"
printOrder="Vertical"
orientation="Portrait"
pageWidth="595"
pageHeight="842"
columnWidth="555"
columnSpacing="0"
leftMargin="20"
rightMargin="20"
topMargin="20"
bottomMargin="20"
whenNoDataType="NoPages"
isTitleNewPage="false"
isSummaryNewPage="false">
<property name="ireport.zoom" value="1.0" />
<property name="ireport.x" value="0" />
<property name="ireport.y" value="6" />
<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="pd_id" isForPrompting="true" class="java.lang.Integer"/>
<parameter name="acl" isForPrompting="true" class="java.lang.String"/>
<queryString><![CDATA[select * from WF_PROC_DEF,acl_module
where pd_id=$P{pd_id}
and acl_module_id = $P{acl}]]></queryString>
<field name="PD_ID" class="java.math.BigDecimal"/>
<field name="PD_NAME" class="java.lang.String"/>
<field name="OLD_PD_ID" class="java.lang.String"/>
<field name="ACL_MODULE_ID" class="java.lang.String"/>
<field name="ACL_MODULE_DESC" class="java.lang.String"/>
<background>
<band height="0" isSplitAllowed="true" >
</band>
</background>
<title>
<band height="79" isSplitAllowed="true" >
<textField isStretchWithOverflow="true" isBlankWhenNull="true" evaluationTime="Now" hyperlinkType="None" hyperlinkTarget="Self" >
<reportElement
x="17"
y="18"
width="100"
height="20"
key="textField"
isRemoveLineWhenBlank="true"/>
<box topBorder="None" topBorderColor="#000000" leftBorder="None" leftBorderColor="#000000" rightBorder="None" rightBorderColor="#000000" bottomBorder="None" bottomBorderColor="#000000"/>
<textElement>
<font/>
</textElement>
<textFieldExpression class="java.lang.String"><![CDATA[$P{pd_id}==1 ? "External Agencies" :
$P{pd_id}==2 ? "Planning, Building & Land" :
$P{pd_id}==3 ? "Composit Forms" :$P{pd_id}]]></textFieldExpression>
</textField>
</band>
</title>
<pageHeader>
<band height="0" isSplitAllowed="true" >
</band>
</pageHeader>
<columnHeader>
<band height="20" isSplitAllowed="true" >
<staticText>
<reportElement
x="0"
y="0"
width="277"
height="20"
key="staticText"/>
<box topBorder="None" topBorderColor="#000000" leftBorder="None" leftBorderColor="#000000" rightBorder="None" rightBorderColor="#000000" bottomBorder="None" bottomBorderColor="#000000"/>
<textElement>
<font/>
</textElement>
<text><![CDATA[PD_ID]]></text>
</staticText>
<staticText>
<reportElement
x="277"
y="0"
width="277"
height="20"
key="staticText"/>
<box topBorder="None" topBorderColor="#000000" leftBorder="None" leftBorderColor="#000000" rightBorder="None" rightBorderColor="#000000" bottomBorder="None" bottomBorderColor="#000000"/>
<textElement>
<font/>
</textElement>
<text><![CDATA[PD_NAME]]></text>
</staticText>
</band>
</columnHeader>
<detail>
<band height="20" isSplitAllowed="true" >
<textField isStretchWithOverflow="false" isBlankWhenNull="false" evaluationTime="Now" hyperlinkType="None" hyperlinkTarget="Self" >
<reportElement
x="0"
y="0"
width="277"
height="20"
key="textField"/>
<box topBorder="None" topBorderColor="#000000" leftBorder="None" leftBorderColor="#000000" rightBorder="None" rightBorderColor="#000000" bottomBorder="None" bottomBorderColor="#000000"/>
<textElement>
<font/>
</textElement>
<textFieldExpression class="java.lang.String"><![CDATA[$F{PD_ID}]]></textFieldExpression>
</textField>
<textField isStretchWithOverflow="false" isBlankWhenNull="false" evaluationTime="Now" hyperlinkType="None" hyperlinkTarget="Self" >
<reportElement
x="277"
y="0"
width="277"
height="20"
key="textField"/>
<box topBorder="None" topBorderColor="#000000" leftBorder="None" leftBorderColor="#000000" rightBorder="None" rightBorderColor="#000000" bottomBorder="None" bottomBorderColor="#000000"/>
<textElement>
<font/>
</textElement>
<textFieldExpression class="java.lang.String"><![CDATA[$F{PD_NAME}]]></textFieldExpression>
</textField>
</band>
</detail>
<columnFooter>
<band height="45" isSplitAllowed="true" >
</band>
</columnFooter>
<pageFooter>
<band height="54" isSplitAllowed="true" >
</band>
</pageFooter>
<summary>
<band height="42" isSplitAllowed="true" >
</band>
</summary>
</jasperReport>
另一个问题:
您有一些关于iReport 2.0.2的简短示例或教程吗?
【问题讨论】:
-
how do I call parameters using ireport- 你是什么意思? -
很抱歉回复晚了,我的意思是如何在 ireport 2.0.2 中调用 if else 语句。使用该参数,因为当我尝试从 4.1.1 转换时它不起作用。我尝试使用 4.1.1 的 if else 条件并尝试转换为 2.0.2。但它不起作用。我已经更新了我的代码。希望你能帮助我。
-
你可以试试这个表达式:
-
我现在试试。非常感谢 alex。:)
标签: jasper-reports