我已经从参数中输入了名称kem的列表。是kem 1,kem 2,kem 3。我已经创建了$x{in,pd_id,Kem}作为参数,但是结果只是显示了来自三个kem的kem 1。我想要的是,当我把kem的名字列表,数据将显示所有的数据。那是kem 1,kem 2,kem 3。这是我的密码:
<?xml version="1.0" encoding="UTF-8"?>
<jasperReport xmlns="http://jasperreports.sourceforge.net/jasperreports" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://jasperreports.sourceforge.net/jasperreports http://jasperreports.sourceforge.net/xsd/jasperreport.xsd" name="testspace" language="javascript" pageWidth="595" pageHeight="842" columnWidth="555" leftMargin="20" rightMargin="20" topMargin="20" bottomMargin="20">
<parameter name="kem" class="java.util.Collection">
<defaultValueExpression><![CDATA[]]></defaultValueExpression>
</parameter>
<queryString>
<![CDATA[select
PD_ID,
PD_NAME
from wf_proc_def where $X{IN,PD_ID,kem}]]>
</queryString>
<field name="PD_ID" class="java.math.BigDecimal"/>
<field name="PD_NAME" class="java.lang.String"/>
<background>
<band splitType="Stretch"/>
</background>
<title>
<band height="79" splitType="Stretch">
<textField isBlankWhenNull="true">
<reportElement x="118" y="24" width="334" height="20"/>
<textElement/>
<textFieldExpression><![CDATA[ ("1".equals($P{kem})) ? "kem1"
:("2".equals($P{kem})) ? "kem2"
:("3".equals($P{kem})) ? "kem3"
:("4".equals($P{kem})) ? "kem4"
:("5".equals($P{kem})) ? "kem5"
:null]]></textFieldExpression>
</textField>
</band>
</title>
</jasperReport>发布于 2012-04-16 06:33:19
我认为参数kem有问题,它必须包含值的列表。您应该初始化这个参数。
这是工作样例(它适用于iReport的示例数据库):
<?xml version="1.0" encoding="UTF-8"?>
<jasperReport ..>
<parameter name="cities" class="java.util.List">
<defaultValueExpression><![CDATA[Arrays.asList(new String[] {"Dallas", "Lyon", "Paris"})]]></defaultValueExpression>
</parameter>
<queryString>
<![CDATA[SELECT ID, CITY FROM ADDRESS WHERE $X{IN,CITY,cities}]]>
</queryString>
<field name="ID" class="java.lang.Integer"/>
<field name="CITY" class="java.lang.String"/>
<title>
<band height="79" splitType="Stretch">
<textField>
<reportElement x="0" y="12" width="100" height="20"/>
<textElement/>
<textFieldExpression><![CDATA[$P{cities}]]></textFieldExpression>
</textField>
</band>
</title>
<detail>
<band height="20" splitType="Stretch">
<textField>
<reportElement x="0" y="0" width="100" height="20"/>
<textElement/>
<textFieldExpression><![CDATA[$F{CITY}]]></textFieldExpression>
</textField>
<textField>
<reportElement x="100" y="0" width="100" height="20"/>
<textElement/>
<textFieldExpression><![CDATA[$F{ID}]]></textFieldExpression>
</textField>
</band>
</detail>
</jasperReport>在iReport预览函数中生成的结果:

更新
如何借助 http://code.google.com/p/guava-libraries/ 库通过键解析值
样本:
<?xml version="1.0" encoding="UTF-8"?>
<jasperReport ..>
<import value="com.google.common.collect.*"/>
<import value="com.google.common.base.*"/>
<parameter name="cities" class="java.util.List">
<defaultValueExpression><![CDATA[Arrays.asList(new String[] {"1", "2", "3"})]]></defaultValueExpression>
</parameter>
<parameter name="citiesMap" class="java.util.Map">
<defaultValueExpression><![CDATA[new ImmutableMap.Builder<String, String>().put("1", "Dallas").put("2", "Lyon").put("3", "Paris").build()]]></defaultValueExpression>
</parameter>
...
<title>
<band height="79" splitType="Stretch">
<textField>
<reportElement x="0" y="12" width="100" height="20"/>
<textElement/>
<textFieldExpression><![CDATA[$P{cities}]]></textFieldExpression>
</textField>
<textField>
<reportElement x="185" y="12" width="100" height="20"/>
<textElement/>
<textFieldExpression><![CDATA[Maps.filterKeys($P{citiesMap}, Predicates.in($P{cities})).values()]]></textFieldExpression>
</textField>
</band>
</title>
...
</jasperReport>其结果将是:

https://stackoverflow.com/questions/10137230
复制相似问题