jkeri Posted July 24, 2017 Share Posted July 24, 2017 I have a $F{NAME} field in my report. If the value of the field is null then I want the background red else just print normally. I have tried PRINT WHEN EXPRESSION and just cant figure out how to do it. Link to comment Share on other sites More sharing options...
darth_fader Posted July 24, 2017 Share Posted July 24, 2017 You can use conditional styles to achieve what you're looking for, here's a reference that should do the trick:http://community.jaspersoft.com/wiki/how-apply-conditional-formatting-your-text-fields Link to comment Share on other sites More sharing options...
hozawa Posted July 25, 2017 Share Posted July 25, 2017 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 More sharing options...
jkeri Posted July 25, 2017 Author Share Posted July 25, 2017 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 More sharing options...
hozawa Posted July 25, 2017 Share Posted July 25, 2017 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 More sharing options...
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now