Jump to content
Changes to the Jaspersoft community edition download ×

Way to express a 'not equals' condition


thosp8246

Recommended Posts

I have searched through the forum and have not found the best way to set up a 'not equals' condition on a 'Print when expression' in iReport (1.3). I have found plenty of samples of an 'equals' condition though.

 

I have a number of fields in my reports that are flags that indicate whether a user has met a condition or not ('Y' or 'N'). When the flag is 'Y', then I want to display a checkbox with a check in it. When the flag is 'N', then I will display an empty checkbox.

 

The general consensus I've seen is that for STRINGS ('Y', 'N'), it would be best to use:

 

   new Boolean($F{SFPAR_GRADE_EXEMPT_FLG}.equals("Y"))

 

But I have not seen anything that definitively (or otherwise) states how to check for a 'not equals' condition. The only things I can guess at are:

 

   new Boolean(!$F{SFPAR_GRADE_EXEMPT_FLG}.equals("Y"))

 

        and

 

   new Boolean($F{SFPAR_GRADE_EXEMPT_FLG} != ("Y"))

 

What would be the best way to check for a 'not equals' condition? And why? Keeping in mind that I want to use the 'equals' condition check for the checkbox with the check in it, and the 'not equals' condition for the empty checkbox.

 

Also, why is '.equals' preferable to ' == ', when the report compiles with the '==' condition, and 'appears' to work (when it doesn't).

Link to comment
Share on other sites

  • Replies 1
  • Created
  • Last Reply

Top Posters In This Topic

Popular Days

Top Posters In This Topic

Hi!

This is a general aspect of Java.

If you have to Strings

y1 = new String("Y");

y2 = new String("Y");

 

y1==y2 is false, as the object references are compared.

y1.equals(y2) is true, as the objects' content is compared.

 

Thus, even using constant strings on one side, you always have to use equals (or equalsIgnoreCase) with strings. Otherwise, you get unexpected "is not equal"s.

 

Thus,

new Boolean(!($F{SFPAR_GRADE_EXEMPT_FLG}.equals("Y")))

or

new Boolean(!($F{SFPAR_GRADE_EXEMPT_FLG}.equalsIgnoreCase("Y")))

is correct.

 

By the way, using N or Y for boolean database fields is not a good custom. Try to use short integers (smallint, int, etc.), with the values "0" for false and "1" (or any other numeric value) for true.

You get much less problems when mapping DB fields to variables, then.

 

Yours,

Sebastian

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