Using conditional formatting in iReport

ireportjasper-reports

I have a report providing a table of data. The report works great so far.
Now I need to colourise some cells according to their content value.
I used to include the colour scheme in the Text Field Expression, for instance:

($F{MyBooleanValue}==true)?"<style backcolor='green'>PASS</style>":"<style backcolor='red'>FAIL</style>"  

That works but it is quite dirty and a hell to manage and re-use.

So I turned to the Conditional formatting feature. I defined a based style called Colourised. Then two very basic conditional styles:

Colourised:  
    opaque = true  
pass:  
    opaque = true  
    Condition Expression = "true"  
    Backcolor = [51,255,51]
fail:  
    opaque = true  
    Condition Expression = "false"  
    Backcolor = [255,102,102]  

This should normally change the background colour of cells to green (independently from the cell value).

Now I try to use this formatting on my cell using the following properties, but the cells remain desperately white.

MyCell:  
    opaque = true  
    Text Field Expression = "$F{MyBooleanValue}"  
    Style = "Colourised"  

I also set the evaluation property

<property name="net.sf.jasperreports.style.evaluation.time.enabled" value="true"/>  

Any hints? Is there something I overlooked?

Best Answer

Ok, after a bit of digging, I found that the cell propertie:

MyCell:
    Markup = "styled"  

needed to be set to:

MyCell:
    Markup = "none"  

Then the background display the proper colour.

Related Topic