Condition expression

Hi,

I have a condition expression in a conditional style that worked fine with JasperReports 4.1.2 but no longer works in 4.5. I have a group called PeriodGroup defined. Here is the xml.

    <style name="alternateStyle" backcolor="white" forecolor="black" fontSize="8">
        <conditionalStyle>
            <conditionExpression>new Boolean($V{PeriodGroup_COUNT}.intValue() % 2 == 0)</conditionExpression>
            <style backcolor="yellow"/>
        </conditionalStyle>
    </style>

I am getting a class cast exception. It appears the PeriodName (which is a String and is the variable that groups the items) is being returned instead of a boolean. Here is the stack trace.

java.lang.ClassCastException: java.lang.String cannot be cast to java.lang.Boolean
    at net.sf.jasperreports.engine.fill.JRFillElementContainer.buildConsolidatedStyle(JRFillElementContainer.java:769)
    at net.sf.jasperreports.engine.fill.JRFillElementContainer.evaluateConditionalStyle(JRFillElementContainer.java:730)
    at net.sf.jasperreports.engine.fill.JRFillElementContainer.evaluateConditionalStyles(JRFillElementContainer.java:718)
    at net.sf.jasperreports.engine.fill.JRFillBand.evaluate(JRFillBand.java:472)
    at net.sf.jasperreports.engine.fill.JRVerticalFiller.fillColumnBand(JRVerticalFiller.java:2021)
    at net.sf.jasperreports.engine.fill.JRVerticalFiller.fillDetail(JRVerticalFiller.java:755)
    at net.sf.jasperreports.engine.fill.JRVerticalFiller.fillReportStart(JRVerticalFiller.java:265)
    at net.sf.jasperreports.engine.fill.JRVerticalFiller.fillReport(JRVerticalFiller.java:128)
    at net.sf.jasperreports.engine.fill.JRBaseFiller.fill(JRBaseFiller.java:836)
    at net.sf.jasperreports.engine.fill.JRBaseFiller.fill(JRBaseFiller.java:765)
    at net.sf.jasperreports.engine.fill.JRFillSubreport.fillSubreport(JRFillSubreport.java:644)
    at net.sf.jasperreports.engine.fill.JRSubreportRunnable.run(JRSubreportRunnable.java:59)
    at net.sf.jasperreports.engine.fill.JRThreadSubreportRunner.run(JRThreadSubreportRunner.java:205)
    at java.lang.Thread.run(Thread.java:619)
 

Do I need to change something? I use this same conditional style in other reports with no issue. I've attached the jrxml file.

Thanks, Mike

msarmc's picture
63
Joined: Sep 1 2010 - 9:53am
Last seen: 2 years 3 months ago

4 Answers:

Hi,

I think your expression should be one of the followings:

(($V{PeriodGroup_COUNT}.intValue() % 2 == 0) ? Boolean.TRUE : Boolean.FALSE)

or

((Integer.valueOf($V{PeriodGroup_COUNT}) % 2 == 0) ? Boolean.TRUE : Boolean.FALSE)

Hope this helps,

Regards.

 

 

augarte's picture
6555
Joined: Jan 27 2010 - 7:20am
Last seen: 3 years 1 week ago

Thanks for the suggestion but unfortunately I still get the same error. There evidently was some internal change from 4.1.2 to 4.5 that no longer correctly handles how the data is arranged. I use that same expression in many other jrxml files and it works fine in 4.5. I've attached a pdf of how the report is supposed to look. I have determined that the first set of data (Resource By Activity) processes correctly. However, when it gets to Resource By Entity (which is a separate data source and jrxml file) I get the error. I determined that the Period Name Week1 (a String) was returned from the expression evaluation instead of a Boolean.

Thanks again for your suggestion. I'll keep investigating.

Mike

msarmc's picture
63
Joined: Sep 1 2010 - 9:53am
Last seen: 2 years 3 months ago

It's a bug introduced in JR 4.1.3 and fixed in SVN trunk revision 5004.  The fix will be included in the 4.5.1 release.

The bug manifests when you have two subreports with identical conditional style expressions.  To workaround it, modify the expression in one of the subreports by adding a space of something that doesn't change the semantics.

Regards,

Lucian

lucianc's picture
87387
Joined: Jul 17 2006 - 1:10am
Last seen: 22 hours 37 min ago

Thank you Lucian.

Mike

msarmc's picture
63
Joined: Sep 1 2010 - 9:53am
Last seen: 2 years 3 months ago
Feedback
randomness