Reputation: 1972
I have put input list of name kem from my parameter. It is kem 1
, kem 2
, kem 3
. I have create $x{in,pd_id,Kem}
as a parameter but the result just show kem 1
from three kem. What I want is when I put list name of kem, the data will display all of the data. That is kem 1
, kem 2
, kem 3
.
This is my code:
<?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>
Upvotes: 0
Views: 10675
Reputation: 22857
I think something wrong with your parameter kem
which must contain the list of values. You should initialize this parameter.
This is working sample (it works with iReport's sample database):
<?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>
The result generated in iReport
preview function:
UPDATE:
How to resolve values by keys with help of google guava library
The sample:
<?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>
The result will be:
Upvotes: 2