[Solved] OR operator in "Print when expression" field

0

Good morning to all,

I'm creating an IReport PDF template using the IReport designer version 3.5.0

I have to print a static text if at least one of two variables are not blank: so in the "Print when expression" field of my static text I wrote this condition 

new Boolean( !$F{riepilogo_totaleDichiarazioni}.equals( "" ) || !$F{riepilogo_totaleDistinte}.equals( "" ) )

It works only if the first operator is true, but if the first is false and the second is true the condition doesn't work. If Itry to reverse the two operators

new Boolean( !$F{riepilogo_totaleDistinte}.equals( "" ) || !$F{riepilogo_totaleDichiarazioni}.equals( "" ) )

it works just if the variable "riepilogo_totaleDistinte is valued. So it seems that the expression evaluate only the first operator and ignores the second.

Is there something wrong in my code?

Thanks in advance for your replies, regards

Giuseppe

 

 

g.dagostino's picture
Joined: Apr 24 2013 - 2:00am
Last seen: 5 years 11 months ago

7 Answers:

2

Hi, 

Try the following: 

!$F{riepilogo_totaleDichiarazioni}.equals( "" ) || !$F{riepilogo_totaleDistinte}.equals( "" ) ? Boolean.TRUE : Boolean.FALSE

Or otherwise this should work also: 

$F{riepilogo_totaleDichiarazioni}.equals( "" ) && $F{riepilogo_totaleDistinte}.equals( "" ) ? Boolean.FALSE : Boolean.TRUE

In this case what you are saying is that the text shoulnd't be printed if both fields (riepilogo_totaleDichiarazoni and riepilogo_totaleDistinte) are empty strings.

Hope this helps.

Regards

 

augarte's picture
501
Joined: Jan 27 2010 - 7:20am
Last seen: 11 months 2 weeks ago
0

First of all...thank you for your reply!

I tried the second solution ($F{riepilogo_totaleDichiarazioni}.equals( "" ) && $F{riepilogo_totaleDistinte}.equals( "" ) ? Boolean.FALSE : Boolean.TRUE) and it works fine if

  1. both fileds are empty
  2. first field (riepilogo_totaleDichiarazioni) is set and the second (riepilogo_totaleDistinte) is empty

but doesn't work fine if the first field is empty and the secondo in set. It seems not evaluate the second condition after the && operator.

Any suggestion?

g.dagostino's picture
Joined: Apr 24 2013 - 2:00am
Last seen: 5 years 11 months ago
0

Which is the value of the second field when it doesn't work? Are both fields string type? Could you attach your .jrxml file? 

augarte's picture
501
Joined: Jan 27 2010 - 7:20am
Last seen: 11 months 2 weeks ago
0

The value of the second filed when it doesn't work is a numeric string (es 5). Both fields are string type.

I attach the .jrxml file. The involved static text  is the first "N°" in the right side of the report.

Thank you for your help!

Regards,

Giuseppe

g.dagostino's picture
Joined: Apr 24 2013 - 2:00am
Last seen: 5 years 11 months ago
0

Your are using an xml file as datasource right? If so, could you also attach the file in order to test your report?

augarte's picture
501
Joined: Jan 27 2010 - 7:20am
Last seen: 11 months 2 weeks ago
0

Try like this:
($F{FIRST} != null && !$F{FIRST}.equals(""))||($F{SECOND} != null && !$F{SECOND}.equals(""))

sanbez's picture
834
Joined: Jan 11 2011 - 2:06am
Last seen: 1 month 4 weeks ago
0

Thank you sanbez your solution works fine...I had to check also the null value!

Thank you augarte for your time!

g.dagostino's picture
Joined: Apr 24 2013 - 2:00am
Last seen: 5 years 11 months ago
Feedback