我想在我的某个报告中使用条件样式来根据条件更改颜色,但它根本不起作用。
我尝试将其与<parameter></parameter>
,<field></field>
和<variable></variable>
一起使用,但在所有情况下我都会遇到同样的错误:
(参数或字段或变量)!
这是我的代码JRXML:
<?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="UserDepart" pageWidth="595" pageHeight="842" columnWidth="555" leftMargin="20" rightMargin="20" topMargin="20" bottomMargin="20" uuid="15289120-bdf0-4edd-905c-647999c3c0cc">
<property name="net.sf.jasperreports.style.evaluation.time.enabled" value="true"/>
<style name="table">
<box>
<pen lineWidth="1.0" lineColor="#000000"/>
</box>
</style>
<style name="table_TH" mode="Opaque" backcolor="#00FFFF">
<box>
<topPen lineWidth="0.5" lineColor="#000000"/>
<bottomPen lineWidth="0.5" lineColor="#000000"/>
</box>
</style>
<!-- Here Is The Probleme !!! -->
<style name="table_CH" mode="Opaque" backcolor="#FF6666">
<box>
<topPen lineWidth="0.5" lineColor="#000000"/>
<bottomPen lineWidth="0.5" lineColor="#000000"/>
</box>
<conditionalStyle>
<conditionExpression><![CDATA[$P{color}.equalsIgnoreCase( "o" )]]></conditionExpression>
<style/>
</conditionalStyle>
</style>
<style name="table_TD" mode="Opaque" backcolor="#FFFFFF">
<box>
<topPen lineWidth="0.5" lineColor="#000000"/>
<bottomPen lineWidth="0.5" lineColor="#000000"/>
</box>
</style>
<subDataset name="New Dataset 1" uuid="2c012e5d-0895-4ef1-8b47-20fd8c6b281f">
<queryString>
<![CDATA[]]>
</queryString>
<field name="nom" class="java.lang.String"/>
<field name="prenom" class="java.lang.String"/>
<field name="profil" class="java.lang.String"/>
<field name="tauxCorrect" class="java.lang.Float"/>
<field name="progres" class="java.lang.Long"/>
</subDataset>
<parameter name="DS1" class="net.sf.jasperreports.engine.data.JRBeanCollectionDataSource"/>
<parameter name="logo" class="java.lang.Object" isForPrompting="false"/>
<!-- Here Is The Parameter i'm using !!! -->
<parameter name="color" class="java.lang.String"/>
<queryString>
<![CDATA[]]>
</queryString>
<field name="departement" class="java.lang.String"/>
<variable name="colorVar" class="java.lang.String">
<variableExpression><![CDATA[$P{color}]]></variableExpression>
</variable>
<background>
<band splitType="Stretch"/>
</background>
<title>
<band height="42" splitType="Stretch">
<image>
<reportElement x="1" y="1" width="127" height="21" uuid="d12193fc-3939-4a94-81c9-28f6e648566a"/>
<imageExpression><![CDATA["C:\\Icons\\logo.png"]]></imageExpression>
</image>
<image>
<reportElement x="388" y="0" width="167" height="32" uuid="4f149815-5c04-4b13-a520-e30202556d92"/>
<imageExpression><![CDATA[$P{logo}]]></imageExpression>
</image>
</band>
</title>
<pageHeader>
<band height="51" splitType="Stretch">
<textField>
<reportElement x="419" y="0" width="136" height="30" uuid="efb55c6b-c6b5-4855-8111-fc621e280922"/>
<textElement>
<font size="18"/>
</textElement>
<textFieldExpression><![CDATA[$F{departement}]]></textFieldExpression>
</textField>
<staticText>
<reportElement x="1" y="0" width="418" height="30" uuid="54fd910a-b9ab-441a-b7e5-a332f67b0504"/>
<textElement>
<font size="18"/>
</textElement>
<text><![CDATA[Etat d'avancement des utilisateurs du département :]]></text>
</staticText>
</band>
</pageHeader>
<detail>
<band height="151" splitType="Stretch">
<componentElement>
<reportElement key="table" style="table" x="2" y="2" width="552" height="147" uuid="1e15cf18-8adf-4bad-9339-04deb8240c82"/>
<jr:table xmlns:jr="http://jasperreports.sourceforge.net/jasperreports/components" xsi:schemaLocation="http://jasperreports.sourceforge.net/jasperreports/components http://jasperreports.sourceforge.net/xsd/components.xsd" whenNoDataType="AllSectionsNoDetail">
<datasetRun subDataset="New Dataset 1" uuid="5ccdd061-c1c3-46a0-bc92-af14bda9b14a">
<datasetParameter name="REPORT_DATA_SOURCE">
<datasetParameterExpression><![CDATA[$P{DS1}]]></datasetParameterExpression>
</datasetParameter>
</datasetRun>
<jr:column width="104" uuid="faddf5bb-759d-4efc-9a3e-9cf16b8cbda2">
<jr:columnHeader style="table_CH" height="30" rowSpan="1">
<box>
<pen lineWidth="1.0" lineStyle="Solid" lineColor="#000000"/>
<topPen lineWidth="1.0" lineStyle="Solid" lineColor="#000000"/>
<leftPen lineWidth="1.0" lineStyle="Solid" lineColor="#000000"/>
<bottomPen lineWidth="1.0" lineStyle="Solid" lineColor="#000000"/>
<rightPen lineWidth="1.0" lineStyle="Solid" lineColor="#000000"/>
</box>
<staticText>
<reportElement x="0" y="0" width="104" height="30" uuid="795dac43-0ff0-482c-89a0-7dac3b27d513"/>
<textElement>
<font size="10"/>
</textElement>
<text><![CDATA[Nom]]></text>
</staticText>
</jr:columnHeader>
<jr:detailCell style="table_TD" height="30" rowSpan="1">
<box>
<pen lineWidth="1.0" lineStyle="Solid" lineColor="#000000"/>
<topPen lineWidth="1.0" lineStyle="Solid" lineColor="#000000"/>
<leftPen lineWidth="1.0" lineStyle="Solid" lineColor="#000000"/>
<bottomPen lineWidth="1.0" lineStyle="Solid" lineColor="#000000"/>
<rightPen lineWidth="1.0" lineStyle="Solid" lineColor="#000000"/>
</box>
<textField isStretchWithOverflow="true">
<reportElement x="0" y="0" width="104" height="30" uuid="195d51a0-9e45-4201-ad67-d3026ce2e72c"/>
<textElement>
<font size="10"/>
</textElement>
<textFieldExpression><![CDATA[$F{nom}]]></textFieldExpression>
</textField>
</jr:detailCell>
</jr:column>
<jr:column width="111" uuid="8a8bc20b-f8b4-45a6-9cbd-68b4a7391426">
<jr:columnHeader style="table_CH" height="30" rowSpan="1">
<box>
<pen lineWidth="1.0" lineStyle="Solid" lineColor="#000000"/>
<topPen lineWidth="1.0" lineStyle="Solid" lineColor="#000000"/>
<leftPen lineWidth="1.0" lineStyle="Solid" lineColor="#000000"/>
<bottomPen lineWidth="1.0" lineStyle="Solid" lineColor="#000000"/>
<rightPen lineWidth="1.0" lineStyle="Solid" lineColor="#000000"/>
</box>
<staticText>
<reportElement x="0" y="0" width="111" height="30" uuid="795dac43-0ff0-482c-89a0-7dac3b27d513"/>
<textElement>
<font size="10"/>
</textElement>
<text><![CDATA[Prenom]]></text>
</staticText>
</jr:columnHeader>
<jr:detailCell style="table_TD" height="30" rowSpan="1">
<box>
<pen lineWidth="1.0" lineStyle="Solid" lineColor="#000000"/>
<topPen lineWidth="1.0" lineStyle="Solid" lineColor="#000000"/>
<leftPen lineWidth="1.0" lineStyle="Solid" lineColor="#000000"/>
<bottomPen lineWidth="1.0" lineStyle="Solid" lineColor="#000000"/>
<rightPen lineWidth="1.0" lineStyle="Solid" lineColor="#000000"/>
</box>
<textField isStretchWithOverflow="true">
<reportElement x="0" y="0" width="111" height="30" uuid="195d51a0-9e45-4201-ad67-d3026ce2e72c"/>
<textElement>
<font size="10"/>
</textElement>
<textFieldExpression><![CDATA[$F{prenom}]]></textFieldExpression>
</textField>
</jr:detailCell>
</jr:column>
<jr:column width="102" uuid="657d2155-3e2f-4f41-ba0a-a17a76598491">
<jr:columnHeader style="table_CH" height="30" rowSpan="1">
<box>
<pen lineWidth="1.0" lineStyle="Solid" lineColor="#000000"/>
<topPen lineWidth="1.0" lineStyle="Solid" lineColor="#000000"/>
<leftPen lineWidth="1.0" lineStyle="Solid" lineColor="#000000"/>
<bottomPen lineWidth="1.0" lineStyle="Solid" lineColor="#000000"/>
<rightPen lineWidth="1.0" lineStyle="Solid" lineColor="#000000"/>
</box>
<staticText>
<reportElement x="0" y="0" width="102" height="30" uuid="795dac43-0ff0-482c-89a0-7dac3b27d513"/>
<textElement>
<font size="10"/>
</textElement>
<text><![CDATA[Profil]]></text>
</staticText>
</jr:columnHeader>
<jr:detailCell style="table_TD" height="30" rowSpan="1">
<box>
<pen lineWidth="1.0" lineStyle="Solid" lineColor="#000000"/>
<topPen lineWidth="1.0" lineStyle="Solid" lineColor="#000000"/>
<leftPen lineWidth="1.0" lineStyle="Solid" lineColor="#000000"/>
<bottomPen lineWidth="1.0" lineStyle="Solid" lineColor="#000000"/>
<rightPen lineWidth="1.0" lineStyle="Solid" lineColor="#000000"/>
</box>
<textField isStretchWithOverflow="true">
<reportElement x="0" y="0" width="102" height="30" uuid="195d51a0-9e45-4201-ad67-d3026ce2e72c"/>
<textElement>
<font size="10"/>
</textElement>
<textFieldExpression><![CDATA[$F{profil}]]></textFieldExpression>
</textField>
</jr:detailCell>
</jr:column>
<jr:column width="131" uuid="d36e39c4-8408-4f2f-865f-787aa3166a7e">
<jr:columnHeader style="table_CH" height="30" rowSpan="1">
<box>
<pen lineWidth="1.0" lineStyle="Solid" lineColor="#000000"/>
<topPen lineWidth="1.0" lineStyle="Solid" lineColor="#000000"/>
<leftPen lineWidth="1.0" lineStyle="Solid" lineColor="#000000"/>
<bottomPen lineWidth="1.0" lineStyle="Solid" lineColor="#000000"/>
<rightPen lineWidth="1.0" lineStyle="Solid" lineColor="#000000"/>
</box>
<staticText>
<reportElement x="1" y="0" width="130" height="30" uuid="795dac43-0ff0-482c-89a0-7dac3b27d513"/>
<textElement>
<font size="10"/>
</textElement>
<text><![CDATA[Taux de réponses correctes]]></text>
</staticText>
</jr:columnHeader>
<jr:detailCell style="table_TD" height="30" rowSpan="1">
<box>
<pen lineWidth="1.0" lineStyle="Solid" lineColor="#000000"/>
<topPen lineWidth="1.0" lineStyle="Solid" lineColor="#000000"/>
<leftPen lineWidth="1.0" lineStyle="Solid" lineColor="#000000"/>
<bottomPen lineWidth="1.0" lineStyle="Solid" lineColor="#000000"/>
<rightPen lineWidth="1.0" lineStyle="Solid" lineColor="#000000"/>
</box>
<textField isStretchWithOverflow="true">
<reportElement x="0" y="0" width="131" height="30" uuid="195d51a0-9e45-4201-ad67-d3026ce2e72c"/>
<textElement>
<font size="10"/>
</textElement>
<textFieldExpression><![CDATA[$F{tauxCorrect}+" %"]]></textFieldExpression>
</textField>
</jr:detailCell>
</jr:column>
<jr:column width="103" uuid="d36e39c4-8408-4f2f-865f-787aa3166a7e">
<jr:columnHeader style="table_CH" height="30" rowSpan="1">
<box>
<pen lineWidth="1.0" lineStyle="Solid" lineColor="#000000"/>
<topPen lineWidth="1.0" lineStyle="Solid" lineColor="#000000"/>
<leftPen lineWidth="1.0" lineStyle="Solid" lineColor="#000000"/>
<bottomPen lineWidth="1.0" lineStyle="Solid" lineColor="#000000"/>
<rightPen lineWidth="1.0" lineStyle="Solid" lineColor="#000000"/>
</box>
<staticText>
<reportElement x="0" y="0" width="103" height="30" uuid="795dac43-0ff0-482c-89a0-7dac3b27d513"/>
<textElement>
<font size="10"/>
</textElement>
<text><![CDATA[Progression Moyenne]]></text>
</staticText>
</jr:columnHeader>
<jr:detailCell style="table_TD" height="30" rowSpan="1">
<box>
<pen lineWidth="1.0" lineStyle="Solid" lineColor="#000000"/>
<topPen lineWidth="1.0" lineStyle="Solid" lineColor="#000000"/>
<leftPen lineWidth="1.0" lineStyle="Solid" lineColor="#000000"/>
<bottomPen lineWidth="1.0" lineStyle="Solid" lineColor="#000000"/>
<rightPen lineWidth="1.0" lineStyle="Solid" lineColor="#000000"/>
</box>
<textField isStretchWithOverflow="true">
<reportElement x="0" y="0" width="103" height="30" uuid="195d51a0-9e45-4201-ad67-d3026ce2e72c"/>
<textElement>
<font size="10"/>
</textElement>
<textFieldExpression><![CDATA[$F{progres}+" %"]]></textFieldExpression>
</textField>
</jr:detailCell>
</jr:column>
</jr:table>
</componentElement>
</band>
</detail>
</jasperReport>
- 已编辑 -
这是错误的完整堆栈跟踪:
Compiling to file... C:\rapports\UserDepartTeste.jasper
net.sf.jasperreports.engine.design.JRValidationException:
Report design not valid : 1. Parameter not found : color
at net.sf.jasperreports.engine.design.JRAbstractCompiler.verifyDesign(JRAbstractCompiler.java:271)
at net.sf.jasperreports.engine.design.JRAbstractCompiler.compileReport(JRAbstractCompiler.java:153)
at com.jaspersoft.ireport.designer.compiler.IReportCompiler.run(IReportCompiler.java:512)
at org.openide.util.RequestProcessor$Task.run(RequestProcessor.java:572)
at org.openide.util.RequestProcessor$Processor.run(RequestProcessor.java:997)
Compilation running time: 31!
我做错了吗?
答案 0 :(得分:2)
问题是您使用<jr:table>
中使用<subDataset>
的样式,因此您无法直接访问到您的主报表参数,需要在此subdataset
<subDataset name="New Dataset 1" uuid="2c012e5d-0895-4ef1-8b47-20fd8c6b281f">
<parameter name="color" class="java.lang.String"/>
<queryString>
<![CDATA[]]>
</queryString>
<field name="nom" class="java.lang.String"/>
<field name="prenom" class="java.lang.String"/>
<field name="profil" class="java.lang.String"/>
<field name="tauxCorrect" class="java.lang.Float"/>
<field name="progres" class="java.lang.Long"/>
</subDataset>
然后在调用jr:table
<jr:table xmlns:jr="http://jasperreports.sourceforge.net/jasperreports/components" xsi:schemaLocation="http://jasperreports.sourceforge.net/jasperreports/components http://jasperreports.sourceforge.net/xsd/components.xsd" whenNoDataType="AllSectionsNoDetail">
<datasetRun subDataset="New Dataset 1" uuid="7fc961fa-4d60-4d02-8145-f6cbfb54cc10">
<datasetParameter name="REPORT_DATA_SOURCE">
<datasetParameterExpression><![CDATA[$P{DS1}]]></datasetParameterExpression>
</datasetParameter>
<datasetParameter name="color">
<datasetParameterExpression><![CDATA[$P{color}]]></datasetParameterExpression>
</datasetParameter>
</datasetRun>
....
</jr:table>