Jump to content
We've recently updated our Privacy Statement, available here ×

How to condtionally apply background color to a field


jkeri

Recommended Posts

  • Replies 4
  • Created
  • Last Reply

Top Posters In This Topic

Top Posters In This Topic

Sample code:

<?xml version="1.0" encoding="UTF-8"?>
<!-- Created with Jaspersoft Studio version 6.4.0.final using JasperReports Library version 6.4.1  -->
<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="Blank_A4_1" pageWidth="595" pageHeight="842" columnWidth="555" leftMargin="20" rightMargin="20" topMargin="20" bottomMargin="20" uuid="81f13a27-6cbc-47dd-b935-4af5dc2ac0a0">
<property name="com.jaspersoft.studio.data.sql.tables" value=""/>
<property name="com.jaspersoft.studio.data.defaultdataadapter" value="TestDataAdapter"/>
<style name="red" mode="Opaque" backcolor="#FFFFFF">
<conditionalStyle>
<conditionExpression><![CDATA[boolean.valueOf($F{NAME} == null)]]></conditionExpression>
<style backcolor="#FF0000"/>
</conditionalStyle>
</style>
<queryString>
<![CDATA[sELECT * FROM test]]>
</queryString>
<field name="id" class="java.lang.Integer"/>
<field name="name" class="java.lang.String"/>
<detail>
<band height="30" splitType="Stretch">
<property name="com.jaspersoft.studio.unit.height" value="pixel"/>
<textField>
<reportElement x="0" y="0" width="278" height="30" uuid="f5458589-56cc-422d-a6da-dc647f1803e8"/>
<textFieldExpression><![CDATA[$F{id}]]></textFieldExpression>
</textField>
<textField>
<reportElement style="red" x="278" y="0" width="277" height="30" uuid="c5476f48-12ed-4a19-9198-a7cf5670bd89">
<property name="com.jaspersoft.studio.unit.y" value="pixel"/>
</reportElement>
<textFieldExpression><![CDATA[$F{NAME}]]></textFieldExpression>
</textField>
</band>
</detail>
</jasperReport>
Link to comment
Share on other sites

I dont know XML well enough to make such a code change. I was thinking that there is some sort of Java code I could put  into the PRINT WHEN EXPRESSION that would test that value of the field and set the backgorund to red

Link to comment
Share on other sites

Just select "Source" tab in Jaspersoft Studio and copy and paste the code. It's the complete JasperReports code and not a function. You'll be able to see how conditional style is setup.

The code to do the conditional style is just "Boolean.valueOf($F{NAME} == null)".

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

×
×
  • Create New...