如何在参数列表多个时设置文本字段 [英] How to set textfield when the parameter list more than one
问题描述
我已经从我的参数中输入了名称kem的输入列表。它是 kem 1
, kem 2
, kem 3
。我已创建 $ x {in,pd_id,Kem}
作为参数,但结果只显示 kem 1
来自三个kem。我想要的是当我列出kem的列表名称时,数据将显示所有数据。那是 kem 1
, kem 2
, kem 3
。
这是我的代码:
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>
推荐答案
我认为你的参数有问题 kem
必须包含值列表。你应该初始化这个参数。
I think something wrong with your parameter kem
which must contain the list of values. You should initialize this parameter.
这是工作样本(它适用于iReport的示例数据库):
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>
在 iReport
预览功能中生成的结果:
The result generated in iReport
preview function:
更新 :
UPDATE:
如何在 google guava 库
样本:
<?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:
这篇关于如何在参数列表多个时设置文本字段的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!