jasper reports - Issue using Groups: How to set backcolor for specific column when the value is null -


i have column called totalhours in report want set color yellow when value of column called outtime null. have created conditional style following details :

<style name="totalhoursbackcolor" linespacing="single">    <conditionalstyle>       <conditionexpression><![cdata[new boolean($f{out_time}.equals( null ))]]>  </conditionexpression>       <style mode="opaque" backcolor="#ffff33" linespacing="single"/>    </conditionalstyle> </style> 

the above code gives following output

 slno.    empid       intime         outime    totalhours  1         100         9:00           13:00       4:00  2         101         9:10           null       yellow  3         105         9:30           13:30                       14:30          null       4         103         9:30           18:30       9:00  5         107         9:40           13:40       8:00                       14:40          18:40      6         108         10:00          null        yellow  7         106         10:00          13:00                       14:00          null              

but, want output follows :

 slno.    empid       intime         outime    totalhours  1         100         9:00           13:00       4:00  2         101         9:10           null       yellow  3         105         9:30           13:30      yellow                       14:30          null        4         103         9:30           18:30       9:00  5         107         9:40           13:40       8:00                       14:40          18:40      6         108         10:00          null        yellow  7         106         10:00          13:00       yellow                       14:00          null              

please find jrxml file :

<?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="hris employee time   sheet" language="groovy" pagewidth="595" pageheight="842" columnwidth="555"   leftmargin="20" rightmargin="20" topmargin="20" bottommargin="20"> <style name="totalhoursbackcolor" linespacing="single"> <conditionalstyle>             <conditionexpression><![cdata[new boolean($f{out_time}.equals( null ))]]></conditionexpression>             <style mode="opaque" backcolor="#ffff33" linespacing="single"/>         </conditionalstyle>     </style>     <parameter name="date" class="java.sql.timestamp">         <defaultvalueexpression><![cdata[]]></defaultvalueexpression>     </parameter>     <querystring>         <![cdata[select hr.employeeid,convert(char(5), tr.in_time, 108) in_time,        convert(char(5), tr.out_time, 108) out_time, convert(varchar(5), sum(datediff(minute, trr.in_time, isnull(trr.out_time, dateadd(hh, 18, dateadd(dd, datediff(dd, 0, trr.in_time), 0))))) / 60) + ':' + convert(varchar(5),sum(datediff(minute, trr.in_time, isnull(trr.out_time, dateadd(hh, 18, dateadd(dd, datediff(dd, 0, trr.in_time), 0))))) % 60) totalhours,        hr.firstname, hr.lastname, hr.employeeno hr_employees hr      left join hr_employee_timesheet tr on (hr.employeeid=tr.employeeid)      left join hr_employee_timesheet trr on (hr.employeeid=trr.employeeid)      (trr.in_time between $p{date} , dateadd(day, 1, $p{date})      ,  tr.in_time between $p{date} , dateadd(day, 1, $p{date}))      , hr.locationid=1 group hr.employeeid, tr.in_time, tr.out_time, hr.firstname,                     hr.lastname,          hr.employeeno, hr.joiningdate order hr.joiningdate asc]]>     </querystring>     <field name="employeeid" class="java.lang.integer"/>     <field name="in_time" class="java.lang.string"/>     <field name="out_time" class="java.lang.string"/>     <field name="totalhours" class="java.lang.string"/>     <field name="firstname" class="java.lang.string"/>     <field name="lastname" class="java.lang.string"/>     <field name="employeeno" class="java.lang.string"/>     <variable name="counter" class="java.lang.integer" incrementtype="group" incrementgroup="employeeserialnumber">         <variableexpression><![cdata[($v{employeeserialnumber_count} == 1) ? $v{counter} + 1 : $v{counter}]]></variableexpression>         <initialvalueexpression><![cdata[0]]></initialvalueexpression>     </variable>     <variable name="outtime_check" class="java.lang.boolean" incrementtype="group" incrementgroup="employeeouttime">         <variableexpression><![cdata[($f{out_time}.equals(null)&& $v{employeeserialnumber_count}==1)?$v{outtime_check}:$f{totalhours}]]></variableexpression>     </variable>     <group name="employeeserialnumber">         <groupexpression><![cdata[$f{employeeno}]]></groupexpression>     </group>     <group name="employeeouttime">         <groupexpression><![cdata[$f{out_time}]]></groupexpression>     </group>     <background>         <band splittype="stretch"/>     </background>     <title>         <band height="79" splittype="stretch">             <image>                 <reportelement x="466" y="19" width="89" height="32"/>                 <imageexpression class="java.lang.string"><![cdata["d:\\timesheet\\logo.png"]]></imageexpression>             </image>         </band>     </title>     <pageheader>         <band height="38" splittype="stretch">             <statictext>                 <reportelement x="125" y="0" width="204" height="20"/>                 <textelement textalignment="center" linespacing="single">                     <font size="12" isbold="true"/>                 </textelement>                 <text><![cdata[employee time sheet - bangalore]]></text>             </statictext>             <textfield pattern="dd mmmmm yyyy">                 <reportelement x="455" y="-2" width="100" height="18"/>                 <textelement linespacing="single">                     <font size="12" isbold="true"/>                 </textelement>                 <textfieldexpression class="java.sql.timestamp"><![cdata[$p{date}]]></textfieldexpression>             </textfield>         </band>     </pageheader>     <columnheader>         <band height="31" splittype="stretch">             <statictext>                 <reportelement x="155" y="7" width="100" height="20"/>                 <textelement textalignment="center" linespacing="single">                     <font isbold="true"/>                 </textelement>                 <text><![cdata[name]]></text>             </statictext>             <statictext>                 <reportelement x="293" y="7" width="86" height="20"/>                 <textelement textalignment="center" linespacing="single">                     <font isbold="true"/>                 </textelement>                 <text><![cdata[in time]]></text>             </statictext>             <statictext>                 <reportelement x="385" y="7" width="76" height="20"/>                 <textelement textalignment="center" linespacing="single">                     <font isbold="true"/>                 </textelement>                 <text><![cdata[out time]]></text>             </statictext>             <statictext>                 <reportelement x="474" y="7" width="59" height="20"/>                 <textelement textalignment="left" linespacing="single">                     <font isbold="true"/>                 </textelement>                 <text><![cdata[total hours ]]></text>             </statictext>             <line>                 <reportelement x="54" y="1" width="1" height="29"/>             </line>             <line>                 <reportelement x="466" y="2" width="1" height="29"/>             </line>             <line>                 <reportelement x="14" y="1" width="527" height="1"/>             </line>             <line>                 <reportelement x="289" y="1" width="1" height="29"/>             </line>             <line>                 <reportelement x="380" y="2" width="1" height="28"/>             </line>             <statictext>                 <reportelement x="57" y="7" width="67" height="20"/>                 <textelement textalignment="center" linespacing="single">                     <font size="10" isbold="true"/>                 </textelement>                 <text><![cdata[employee no.]]></text>             </statictext>             <line>                 <reportelement x="128" y="2" width="1" height="28"/>             </line>             <line>                 <reportelement x="430" y="30" width="111" height="1"/>             </line>             <statictext>                 <reportelement x="20" y="7" width="30" height="20"/>                 <textelement textalignment="center" linespacing="single">                     <font size="10" isbold="true"/>                 </textelement>                 <text><![cdata[sl no.]]></text>             </statictext>             <line>                 <reportelement x="14" y="2" width="1" height="29"/>             </line>         </band>     </columnheader>     <detail>         <band height="22" splittype="stretch">             <line>                 <reportelement x="54" y="0" width="1" height="22"/>             </line>             <line>                 <reportelement x="466" y="0" width="1" height="22"/>             </line>             <line>                 <reportelement x="13" y="-1" width="416" height="1"/>             </line>             <line>                 <reportelement x="14" y="21" width="415" height="1"/>             </line>             <line>                 <reportelement x="541" y="-29" width="1" height="50"/>             </line>             <line>                 <reportelement x="289" y="0" width="1" height="21"/>             </line>             <line>                 <reportelement x="380" y="-1" width="1" height="22"/>             </line>             <textfield>                 <reportelement isprintrepeatedvalues="false" x="68" y="1" width="44" height="20"/>                 <textelement textalignment="center" linespacing="single">                     <font isbold="false"/>                 </textelement>                 <textfieldexpression class="java.lang.string"><![cdata[$f{employeeno}]]></textfieldexpression>             </textfield>             <textfield>                 <reportelement isprintrepeatedvalues="false" x="134" y="1" width="148" height="20"/>                 <textelement textalignment="left" linespacing="single"/>                 <textfieldexpression class="java.lang.string"><![cdata[$f{firstname} + " " + $f{lastname}]]></textfieldexpression>             </textfield>             <line>                 <reportelement x="128" y="0" width="1" height="22"/>             </line>             <line>                 <reportelement x="430" y="21" width="111" height="1"/>             </line>             <textfield>                 <reportelement x="293" y="1" width="76" height="20"/>                 <textelement textalignment="center" linespacing="single"/>                 <textfieldexpression class="java.lang.string"><![cdata[$f{in_time}]]></textfieldexpression>             </textfield>             <textfield pattern="" isblankwhennull="true">                 <reportelement mode="transparent" x="384" y="1" width="76" height="20"/>                 <textelement textalignment="center" linespacing="single"/>                 <textfieldexpression class="java.lang.string"><![cdata[$f{out_time}]]></textfieldexpression>             </textfield>             <textfield>                 <reportelement style="totalhoursbackcolor" isprintrepeatedvalues="false" x="477" y="1" width="62" height="20"/>                 <textelement textalignment="left" linespacing="single"/>                 <textfieldexpression class="java.lang.string"><![cdata[$f{totalhours}]]></textfieldexpression>             </textfield>             <line>                 <reportelement x="14" y="1" width="1" height="20"/>             </line>             <textfield>                 <reportelement isprintrepeatedvalues="false" x="24" y="2" width="25" height="19">                     <printwhenexpression><![cdata[$v{employeeserialnumber_count}==1]]></printwhenexpression>                 </reportelement>                 <textelement linespacing="single"/>                 <textfieldexpression class="java.lang.integer"><![cdata[$v{counter}]]></textfieldexpression>             </textfield>         </band>     </detail>     <columnfooter>         <band height="45" splittype="stretch"/>     </columnfooter>     <pagefooter>         <band height="54" splittype="stretch">             <textfield>                 <reportelement x="435" y="34" width="80" height="20"/>                 <textelement textalignment="right" linespacing="single"/>                 <textfieldexpression class="java.lang.string"><![cdata["page "+$v{page_number}+" of"]]></textfieldexpression>             </textfield>             <textfield evaluationtime="report">                 <reportelement x="515" y="34" width="40" height="20"/>                 <textelement linespacing="single"/>                 <textfieldexpression class="java.lang.string"><![cdata[" " + $v{page_number}]]></textfieldexpression>             </textfield>         </band>     </pagefooter>     <summary>         <band height="41" splittype="stretch"/>     </summary> </jasperreport> 

could please me how it

you should change evaluationtime attribute of textfield styled text (with $f{totalhours} expression) band value.

the working sample.

the input data, csv data source:

employeeid,in_time,out_time,totalhours,firstname,lastname,employeeno 101,9:00,13:00,4:00,filippo,inzaghi,1 102,10:00,,,zineddin,zidan,2 102,10:00,,,zineddin,zidan,2 103,10:00,15:00,5:00,andriy,shevchenko,3 103,10:00,16:00,6:00,andriy,shevchenko,3 103,10:00,,,andriy,shevchenko,3 104,8:00,15:00,7:00,gennaro,gattuso,4 104,8:00,10:00,2:00,gennaro,gattuso,4 

the jrxml file:

<?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="hris employee time   sheet" language="groovy" pagewidth="595" pageheight="842" columnwidth="555" leftmargin="20" rightmargin="20" topmargin="20" bottommargin="20">     <style name="totalhoursbackcolor" linespacing="single">         <conditionalstyle>             <conditionexpression><![cdata[new boolean($f{out_time}.length()==0)]]></conditionexpression>             <style mode="opaque" backcolor="#ffff33" linespacing="single"/>         </conditionalstyle>     </style>     <querystring>         <![cdata[]]>     </querystring>     <field name="employeeid" class="java.lang.integer"/>     <field name="in_time" class="java.lang.string"/>     <field name="out_time" class="java.lang.string"/>     <field name="totalhours" class="java.lang.string"/>     <field name="firstname" class="java.lang.string"/>     <field name="lastname" class="java.lang.string"/>     <field name="employeeno" class="java.lang.string"/>     <variable name="counter" class="java.lang.integer" incrementtype="group" incrementgroup="employeeserialnumber">         <variableexpression><![cdata[($v{employeeserialnumber_count} == 1) ? $v{counter} + 1 : $v{counter}]]></variableexpression>         <initialvalueexpression><![cdata[0]]></initialvalueexpression>     </variable>     <variable name="outtime_check" class="java.lang.boolean" incrementtype="group" incrementgroup="employeeouttime">         <variableexpression><![cdata[($f{out_time}.equals(null)&& $v{employeeserialnumber_count}==1)?$v{outtime_check}:$f{totalhours}]]></variableexpression>     </variable>     <group name="employeeserialnumber">         <groupexpression><![cdata[$f{employeeno}]]></groupexpression>     </group>     <group name="employeeouttime">         <groupexpression><![cdata[$f{out_time}]]></groupexpression>     </group>     <columnheader>         <band height="31" splittype="stretch">             <statictext>                 <reportelement x="135" y="0" width="183" height="31"/>                 <box>                     <toppen linewidth="1.0"/>                     <leftpen linewidth="1.0"/>                     <bottompen linewidth="1.0"/>                     <rightpen linewidth="1.0"/>                 </box>                 <textelement textalignment="center" verticalalignment="middle" linespacing="single">                     <font isbold="true"/>                 </textelement>                 <text><![cdata[name]]></text>             </statictext>             <statictext>                 <reportelement x="318" y="0" width="86" height="31"/>                 <box>                     <toppen linewidth="1.0"/>                     <leftpen linewidth="1.0"/>                     <bottompen linewidth="1.0"/>                     <rightpen linewidth="1.0"/>                 </box>                 <textelement textalignment="center" verticalalignment="middle" linespacing="single">                     <font isbold="true"/>                 </textelement>                 <text><![cdata[in time]]></text>             </statictext>             <statictext>                 <reportelement x="404" y="0" width="76" height="31"/>                 <box>                     <toppen linewidth="1.0"/>                     <leftpen linewidth="1.0"/>                     <bottompen linewidth="1.0"/>                     <rightpen linewidth="1.0"/>                 </box>                 <textelement textalignment="center" verticalalignment="middle" linespacing="single">                     <font isbold="true"/>                 </textelement>                 <text><![cdata[out time]]></text>             </statictext>             <statictext>                 <reportelement x="480" y="0" width="59" height="31"/>                 <box>                     <toppen linewidth="1.0"/>                     <leftpen linewidth="1.0"/>                     <bottompen linewidth="1.0"/>                     <rightpen linewidth="1.0"/>                 </box>                 <textelement textalignment="left" verticalalignment="middle" linespacing="single">                     <font isbold="true"/>                 </textelement>                 <text><![cdata[total hours ]]></text>             </statictext>             <statictext>                 <reportelement x="50" y="0" width="85" height="31"/>                 <box>                     <toppen linewidth="1.0"/>                     <leftpen linewidth="1.0"/>                     <bottompen linewidth="1.0"/>                     <rightpen linewidth="1.0"/>                 </box>                 <textelement textalignment="center" verticalalignment="middle" linespacing="single">                     <font size="10" isbold="true"/>                 </textelement>                 <text><![cdata[employee id]]></text>             </statictext>             <statictext>                 <reportelement x="0" y="0" width="50" height="31"/>                 <box>                     <toppen linewidth="1.0"/>                     <leftpen linewidth="1.0"/>                     <bottompen linewidth="1.0"/>                     <rightpen linewidth="1.0"/>                 </box>                 <textelement textalignment="center" verticalalignment="middle" linespacing="single">                     <font size="10" isbold="true"/>                 </textelement>                 <text><![cdata[sl no.]]></text>             </statictext>         </band>     </columnheader>     <detail>         <band height="22" splittype="stretch">             <statictext>                 <reportelement isprintrepeatedvalues="false" mode="opaque" x="480" y="0" width="59" height="22">                     <printwhenexpression><![cdata[boolean.valueof(1==1)]]></printwhenexpression>                 </reportelement>                 <box>                     <toppen linewidth="1.0"/>                     <leftpen linewidth="1.0"/>                     <bottompen linewidth="1.0"/>                     <rightpen linewidth="1.0"/>                 </box>                 <textelement linespacing="single" markup="none"/>                 <text><![cdata[]]></text>             </statictext>             <statictext>                 <reportelement isprintrepeatedvalues="false" mode="opaque" x="50" y="0" width="85" height="22">                     <printwhenexpression><![cdata[boolean.valueof(1==1)]]></printwhenexpression>                 </reportelement>                 <box>                     <toppen linewidth="1.0"/>                     <leftpen linewidth="1.0"/>                     <bottompen linewidth="1.0"/>                     <rightpen linewidth="1.0"/>                 </box>                 <textelement linespacing="single" markup="none"/>                 <text><![cdata[]]></text>             </statictext>             <textfield>                 <reportelement x="318" y="0" width="86" height="22"/>                 <box leftpadding="10">                     <toppen linewidth="1.0"/>                     <leftpen linewidth="1.0"/>                     <bottompen linewidth="1.0"/>                     <rightpen linewidth="1.0"/>                 </box>                 <textelement textalignment="center" linespacing="single"/>                 <textfieldexpression class="java.lang.string"><![cdata[$f{in_time}]]></textfieldexpression>             </textfield>             <textfield pattern="" isblankwhennull="false">                 <reportelement mode="transparent" x="404" y="0" width="76" height="22"/>                 <box leftpadding="10">                     <toppen linewidth="1.0"/>                     <leftpen linewidth="1.0"/>                     <bottompen linewidth="1.0"/>                     <rightpen linewidth="1.0"/>                 </box>                 <textelement textalignment="center" linespacing="single"/>                 <textfieldexpression class="java.lang.string"><![cdata[$f{out_time}]]></textfieldexpression>             </textfield>             <textfield evaluationtime="band">                 <reportelement style="totalhoursbackcolor" isprintrepeatedvalues="false" x="480" y="0" width="59" height="22"/>                 <box leftpadding="10">                     <toppen linewidth="1.0"/>                     <leftpen linewidth="1.0"/>                     <bottompen linewidth="1.0"/>                     <rightpen linewidth="1.0"/>                 </box>                 <textelement textalignment="left" linespacing="single"/>                 <textfieldexpression class="java.lang.string"><![cdata[$f{totalhours}]]></textfieldexpression>             </textfield>             <statictext>                 <reportelement isprintrepeatedvalues="false" mode="opaque" x="0" y="0" width="50" height="22">                     <printwhenexpression><![cdata[boolean.valueof(1==1)]]></printwhenexpression>                 </reportelement>                 <box>                     <toppen linewidth="1.0"/>                     <leftpen linewidth="1.0"/>                     <bottompen linewidth="1.0"/>                     <rightpen linewidth="1.0"/>                 </box>                 <textelement linespacing="single" markup="none"/>                 <text><![cdata[]]></text>             </statictext>             <textfield>                 <reportelement isprintrepeatedvalues="false" x="50" y="0" width="85" height="22"/>                 <box leftpadding="10">                     <toppen linewidth="1.0"/>                     <leftpen linewidth="1.0"/>                     <bottompen linewidth="1.0"/>                     <rightpen linewidth="1.0"/>                 </box>                 <textelement textalignment="center" linespacing="single">                     <font isbold="false"/>                 </textelement>                 <textfieldexpression class="java.lang.string"><![cdata[$f{employeeid}]]></textfieldexpression>             </textfield>             <textfield>                 <reportelement isprintrepeatedvalues="false" x="135" y="0" width="183" height="22"/>                 <box leftpadding="10">                     <toppen linewidth="1.0"/>                     <leftpen linewidth="1.0"/>                     <bottompen linewidth="1.0"/>                     <rightpen linewidth="1.0"/>                 </box>                 <textelement textalignment="left" linespacing="single"/>                 <textfieldexpression class="java.lang.string"><![cdata[$f{firstname} + " " + $f{lastname}]]></textfieldexpression>             </textfield>             <textfield>                 <reportelement isprintrepeatedvalues="false" x="0" y="0" width="50" height="22">                     <printwhenexpression><![cdata[$v{employeeserialnumber_count}==1]]></printwhenexpression>                 </reportelement>                 <box leftpadding="10">                     <toppen linewidth="1.0"/>                     <leftpen linewidth="1.0"/>                     <bottompen linewidth="1.0"/>                     <rightpen linewidth="1.0"/>                 </box>                 <textelement linespacing="single"/>                 <textfieldexpression class="java.lang.integer"><![cdata[$v{counter}]]></textfieldexpression>             </textfield>             <statictext>                 <reportelement isprintrepeatedvalues="false" mode="opaque" x="135" y="0" width="183" height="22">                     <printwhenexpression><![cdata[boolean.valueof(1==1)]]></printwhenexpression>                 </reportelement>                 <box>                     <toppen linewidth="1.0"/>                     <leftpen linewidth="1.0"/>                     <bottompen linewidth="1.0"/>                     <rightpen linewidth="1.0"/>                 </box>                 <textelement linespacing="single" markup="none"/>                 <text><![cdata[]]></text>             </statictext>         </band>     </detail>     <pagefooter>         <band height="54" splittype="stretch">             <textfield>                 <reportelement x="435" y="34" width="80" height="20"/>                 <textelement textalignment="right" linespacing="single"/>                 <textfieldexpression class="java.lang.string"><![cdata["page "+$v{page_number}+" of"]]></textfieldexpression>             </textfield>             <textfield evaluationtime="report">                 <reportelement x="515" y="34" width="40" height="20"/>                 <textelement linespacing="single"/>                 <textfieldexpression class="java.lang.string"><![cdata[" " + $v{page_number}]]></textfieldexpression>             </textfield>         </band>     </pagefooter> </jasperreport> 

the result (via preview function in ireport):

preview in ireport

if did not change evaluationtime attribute textfield (default value now) result be:

preview in ireport

note: i've used ireport 3.7.6.


Comments