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

Condition expression


msarmc

Recommended Posts

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

Link to comment
Share on other sites

  • Replies 4
  • Created
  • Last Reply

Top Posters In This Topic

Top Posters In This Topic

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

Link to comment
Share on other sites

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

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...