Print When Expression...

0

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)

0

-15

60

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"
]]></printWhenExpression>
    </reportElement>
    <textElement/>
    <textFieldExpression class="java.lang.String"><![CDATA[$V{time_status}]]></textFieldExpression>
   </textField>

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

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

buyakl's picture
6
Joined: Nov 24 2009 - 11:37am
Last seen: 9 years 5 months ago

6 Answers:

0

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
thangalin's picture
360
Joined: Apr 21 2008 - 4:34am
Last seen: 8 months 4 weeks ago
0

THANK YOU SO MUCH! It works!

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 ;-)

buyakl's picture
6
Joined: Nov 24 2009 - 11:37am
Last seen: 9 years 5 months ago
0

You are most welcome.

iReport is pretty amazing. When you get into subreports then you get to see its power unleashed.

Good luck!

thangalin's picture
360
Joined: Apr 21 2008 - 4:34am
Last seen: 8 months 4 weeks ago
0

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(TM) 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!

buyakl's picture
6
Joined: Nov 24 2009 - 11:37am
Last seen: 9 years 5 months ago
0

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.

thangalin's picture
360
Joined: Apr 21 2008 - 4:34am
Last seen: 8 months 4 weeks ago
0

Hi,

Can anyone please help me to know how to print minus sign when checkbox is check and plus value when the checkbox in uncheck in jasper report?

 

 

 

javahelper's picture
Joined: Jan 23 2014 - 9:13pm
Last seen: 2 years 3 months ago
Feedback
randomness