Jump to content

Print When Expression...


Recommended Posts

I've searched the forums for a couple days now and have found a few topics that have "helped". I mean that in a way where I've gathered more knowledge about java than I previously had. Here's my problem:

I need to compare shipping times and arrivals to setup a field that states "On Time" or "Late". In SQL, I've made an equation that breaks the date into minutes and compares shipping appointment and arrival. If it's on time, the field produced in SQL will show a 0 (zero) or negative number. If it's late, the field will show a positive number. For example...

so_difference (the name of my field that calculates the difference of minutes between appointment and arrival)




I've made a variable field in iReport   $V{time_status}   and would like it to show "On Time" where the 0 and -15 are and "Late" where the 60 is. It seems like a very easy fix, but I'm not a java expert (not even a beginner) and I feel like all I'm missing is a parenthesis, qoutation, or colon somewhere and that would be it. I'm using iReport 3.5.2 and setting up a variable in the report to express "On Time", "Late", and "No Data" where null would appear (the text in red is where I put the formula in "Print When Expression" in iReport)

Here's is the XML statement:

<textField isBlankWhenNull="false">
    <reportElement x="579" y="0" width="81" height="13">
     <printWhenExpression><![CDATA[ ($F{so_difference}.intValue()<=0)?"On Time":
($F{so_difference}.intValue()>=1)?"Late":"No Data"
    <textFieldExpression class="java.lang.String"><![CDATA[$V{time_status}]]></textFieldExpression>

All that is returned in this field is "null". What am I doing wrong?

Thank you so much for your help in advance...

Link to comment
Share on other sites

  • Replies 6
  • Created
  • Last Reply

Top Posters In This Topic

Top Posters In This Topic

One solution would be to use multiple texts with different PrintWhenExpression statements. For example:

On Time - PrintWhenExpression: new Boolean( $F{so_difference}.intValue() <= 0 ).booleanValue()
Late - PrintWhenExpression: new Boolean( $F{so_difference}.intValue() >= 1 ).booleanValue()
No Data - PrintWhenExpression: new Boolean( $F{so_difference} == null ).booleanValue()

(I do not recall if .booleanValue() is required; you might have to remove it -- including the period.)

The reason might be because when $F{so_difference} is null, trying to call .intValue() will cause an error. That being the case, you might have to check for null values beforehand:

On Time - PrintWhenExpression: $F{so_difference} == null ? Boolean.FALSE : new Boolean( $F{so_difference}.intValue() <= 0 ).booleanValue()
Late - PrintWhenExpression: $F{so_difference} == null ? Boolean.FALSE : new Boolean( $F{so_difference}.intValue() >= 1 ).booleanValue()

Personally, I dislike "hiding" static text values within code. I find reports easier to change when all static text values stand alone. The overlap might be confusing, but a future version of iReport might have layers to help resolve the overlap problem.

Post Edited by thangalin at 03/16/2010 18:25
Link to comment
Share on other sites


We just got iReport for our company and I think you may have shown us more of the capabilities of this program. He thought it would definetly be better than the one we had before, but I may be able to convince him to buy me a book for JAVA now to increase the magnitude of what this can do!

It's not as beginner friendly as our previous one, but it can do WAY more than the report designer we had before! Thank you SOOooo much thangalin! You are a life saver! (I made sure your Karma went up ;-)

Link to comment
Share on other sites

thangalin, (or anyone else reading this forum thread)

Would you know where I can start my journey on learning the JAVA expressions/language iReport uses? I can always get a book or search online, but exactly what version am i looking at here? According to the Help/About, my iReport is using

Java: 1.6.0_17; Java HotSpot Client VM 14.3-b01


I would really like to be able to start understanding ALL the terminology and language in iReport to increase the programs funtionality. Outside of this stump, I've successfully made a very nice report with subreports that really cleaned up our old version, but I feel like I have come to the end of my luck and will need to start learning alot more... otherwise I'll just end up posting on here once a week.


You guys are great and all, but I'd like to carry my own weight too! ;-)


Thank you everyone!

Link to comment
Share on other sites

There are books, such as the iReport Ultimate Development Guide. It does not cover the Java language, nor does it go into a lot of detail about different types of charts (and their options). However, it covers the basics extremely well.

Since Java is a full programming language, to gain the most out of iReport, it would be good to learn about Java itself. However, being a programming language, Java is fairly complex. Fortunately, iReport hides a lot of the technical details and nuances of Java from its users. The only way you could have known that you cannot run a method (such as .booleanValue()) on a null result is by understanding the Java language. Or asking someone.

Link to comment
Share on other sites

  • 3 years later...

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